views:

149

answers:

2

I have a map with hotspots for each state (done in Expression Blend). I capture each MouseEnter of the state (1 thru 50). I pass that into my Domain Data Source:

    Dim activebox As Path = TryCast(sender, Path)
    activebox.Fill = mouseOverColor
    Dim StateID As Integer = CInt(Right(activebox.Name, 2))

     Dim _StateContext As New StateContext
     myDataGrid.ItemsSource = _StateContext.States
    _StateContext.Load(_StateContext.GetStateByStateIDQuery(StateID.Text))

The above works fine for a datagrid, listbox and even a dataform.

But I created a popup with a stackpanel that has textblocks.

    popupStatesBox.DataContext = ??????????????
    popupStatesBox.IsOpen = True   'popup does open but has no data

-- popupStatesBox.xaml

  <Popup x:Name="popupStatsBox" Margin="8,35,0,8" DataContext="{Binding}" 
       IsOpen="false" Width="268" HorizontalAlignment="Left">
      <StackPanel x:Name="Layout" Background="Black">
 <TextBlock x:Name="tbState" Text="{Binding StateName />
 <TextBlock x:Name="tbAbbrev" Text="{Binding Abbreviation}"  /> 
      </StackPanel>
  </Popup>

How do I get the textblocks to display the values from the _StateContext.
StackPanel has DataContext but no ItemsSource. What am I missing?

A: 

Assuming you've already loaded the States collection in the context then this is probably the sort of thing you are after:-

 popupStatsBox.DataContext = _StateContext.States.FirstOrDefault(Function(s) s.StateID = StateID)

Note that encoding data into element names is not a good practice, look into creating an attached property and store the state ID as an attached property of each Path.

To be honest I would be tempted to create a custom control derived from a Selector to create a StatesSelector control.

You would bind the ItemsSource property to your States collection. As the mouse moves about assign the appropiate item from the ItemsSource to the SelectedItem property.

However that may be taking things a little too far.

AnthonyWJones
A: 

Thanks Anthony. It's working almost as I expect.

There seems to be a delay on the loading of the data on mouseenter.

When I mouseenter an image I pass a numeric value, the popup appears without data. If I mouseout then mouseenter again, the popup appears with data.

BTW, you mentioned "To be honest I would be tempted to create a custom control derived from a Selector to create a StatesSelector control."

Where can I find more info on that '...custom control....'?

tfisher