I have a Nested ListBox
. On inner listbox mouse double click event, I need to open a new window based on some logic and for that I need the inner ListBox SelectedItem and its corresponding Outer ListBox SelectedItem
. How can get this in an MVVM manner?
<ListBox ItemsSource="{Binding OuterCollection}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding OuterProperty1}" />
<ListBox Width="200" ItemsSource="{Binding InnerCollection}">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding InnerProperty1}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Things to remember:
1) There is no relation between the inner collection and outer collection item.
2) I'm using MVVMLight Toolkit and as a temporary solution I just passes inner ListBox Mouse Double Click event argument to the View model and traverse through the tree to find the Outer ListBox item. I know this is against the MVVM rules, so how can I do it in a proper MVVM manner?