views:

42

answers:

1

I have a datagrid which is populated from a web service. I want to fill a form based on the selected item in the datagrid.

This is what I use to set the DataContext (Which is a grid)

private void PublisherSearchList_SelectionChanged(object sender, SelectionChangedEventArgs e)
{    
    this.PublisherItem.DataContext = (Publisher)PublisherSearchList.SelectedItem;   
}

XAML

<Grid Name="PublisherItem" Width="390" Margin="5" > 
      <Grid.ColumnDefinitions>
           <ColumnDefinition Width="200" />
      </Grid.ColumnDefinitions>
      <Grid.RowDefinitions>
           <RowDefinition Height="20"></RowDefinition>
      </Grid.RowDefinitions>
      <TextBox Name="CompanyName" DataContext="{Binding PublisherName}"
               Grid.Column="0" Grid.Row="0"></TextBox>                    
</Grid>

How can this be done?

A: 

Have you tried to bind your control with properties?
For example if your Publisher class has property Name than you can bind this way

DataContext="{Binding Publisher, Path=Name}"
Samvel Siradeghyan
Tried and it didnt work
Steven
Any other ideas?
Steven
Unfortunatly no
Samvel Siradeghyan