0
votes

I have two ListBoxes. I'm trying to setup a master-detail relationship between them.

So, TYPE_MASTER and TYPE_DETAIL are both EF entities. TYPE_MASTER has a property called TYPE_DETAIL which is a collection of related TYPE_DETAIL entities. ListBox1's ItemsSource is bound to an ObservableCollection, ListBox2's ItemsSource is bound to the TYPE_DETAIL property of the SelectedItem of ListBox1.

The problem is that SelectedItem returns an object, rather than a TYPE_MASTER, so my binding for ListBox2 tells me that it can't resolve the TYPE_DETAIL property in the data context of type object. How do bind ListBox2's itemssource to the collection of TYPE_DETAILs on ListBox1's SelectedItem?

Note - I can't directly reference the object types of the entities, as they live in the DAL, and we have a strict company policy against creating dependencies from the presentation layer to the DAL.

My code:

    <StackPanel Name="SpMaster" Orientation="Vertical" Grid.Row="0" ToolTip="{Binding Source={x:Static robertGlobals:Messages.SelectMaster}}">
        <TextBlock Name="TxtbMaster" Style="{StaticResource HeadingFourBrown}" Text="Masters" Grid.Row="0"></TextBlock>
        <ListBox Name="ListMaster" ItemsSource="{Binding PageModel.PageSelection.Masters}" Style="{StaticResource ClearListbox}"
                 DisplayMemberPath="DESCRIPTION">
        </ListBox>
    </StackPanel>
    <StackPanel Name="SpDetail" Orientation="Vertical" Grid.Row="1" ToolTip="{Binding Source={x:Static robertGlobals:Messages.DragDetail}}">
        <TextBlock Name="TxtbDetails" Style="{StaticResource HeadingFourBrown}" Text="Available Details" Grid.Row="0"></TextBlock>
        <ListBox Name="ListDetails" ItemsSource="{Binding ElementName=ListMaster, Path=SelectedItem.TYPE_DETAIL}" 
                 Style="{StaticResource ClearListbox}" DisplayMemberPath="NAME"></ListBox>
    </StackPanel>
1

1 Answers

0
votes

Simple answer: everything is configured correctly, except that the DisplayMemberPath references the wrong field name. Corrected that and everything cleared up. It's the simple things.