views:

17

answers:

1

I defined a domain context as a user resource

<UserControl.Resources>
    <my:ParkDomainContext x:Key="parkDomainContext" />
 </UserControl.Resources>

I have bounded to table query result to this domain context in my code behind

_parkDomainContext = this.Resources["parkDomainContext"] as ParkDomainContext;
_parkDomainContext.Load(_parkDomainContext.GetLocationsQuery(), LoadLocationComplete, null);
_parkDomainContext.Load(_parkDomainContext.GetParksQuery(), LoadParkComplete, null);

After this I have bounded the static domain context to a combo box as following

<ComboBox x:Name="cboLocation" Grid.Column="1" Grid.Row="1"  
                      ItemsSource="{Binding Path=Locations, Source={StaticResource parkDomainContext}}"
                      SelectedItem="{Binding Path=Locations, Mode=TwoWay}"
                      DisplayMemberPath="ParkLocation"
            />

It's working fine but when I bind the same domain context to a textbox as follows:

<TextBox Grid.Column="1" Grid.Row="0" Height="23" HorizontalAlignment="Left" Margin="3" Name="locationIDTextBox"
                 VerticalAlignment="Center" Width="120"
                  Text="{Binding Source={StaticResource parkDomainContext}, Path=Locations.ParkLocation}" >

It doesn't show me any result .

I know that my domain context has query result and there must be something wrong in binding it to Textbox.

PLease let me know the solution..

A: 

You need to have somewhere a variable holding the current location and bind the textbox to it. Instead, what you have right now is a binding of ComboBox.SelectedItem to the list of locations (which will not work).

Edited after OP comment: Add to <UserControl.Resources>

<my:Location x:Key="currentLocation" />

Then change the ComboBox to:

SelectedItem="{Binding Source={StaticResource currentLocation}, Mode=TwoWay}"

Then the TextBox:

Text={Binding Source={StaticResource currentLocation}, Mode=TwoWay}"

Notes:

  1. Please change the type name and namespace of Location to your actual type
  2. This is not really a recommended way of doing stuff. Usually, you have a class with the necessary properties for your XAML and set the DataContext of your UserControl (or Window) to an instance of this class.
Timores
Ya,I feel the same. but how?