Given the data structure
{
Collection elements;
String LocationName;
}
And a ComboBox that is bound to a collection of such items (described in the structure) with DisplayMemberPath set to LocationName, how do I bind a datagrid to the SelectedItem.Elements of said combo box in XAML?
By my understanding the SelectedItem property of the combo box will return LocationName. I would need to move up in the data context of the structure then attach SourceItems to Elements. Correct? However I cannot seem to make it work with the Binding markup.
P.S. I am working on rigging a GUI with sample data.
Thank you.
Update 1: Code looks as follows:
<ComboBox x:Name="ComboBox1"
ItemsSource="{Binding AdSources, Mode=OneWay}"
DisplayMemberPath="NameProperty" />
<ComboBox x:Name="ComboBox2"
ItemsSource="{Binding SelectedItem.CollectionProperty, ElementName=ComboBox1, Mode=OneWay}"
DisplayMemberPath="NameProperty2" />
<data:DataGrid x:Name="DataGrid"
ItemsSource="{Binding SelectedItem.CollectionProperty, ElementName=ComboBox2, Mode=OneWay}">
<data:DataGrid.Columns>
<data:DataGridTextColumn Header="Column1" Binding="{Binding Property1}"/>
</data:DataGrid.Columns>
</data:DataGrid>
The
SelectedItemwill point to the entire object, that’s why you specified aDisplayMemberPathforLocationName. The entire object is selected, but only the location name is displayed.You can bind to
SelectedItem.Elements– if that doesn’t work, your problem is somewhere else.