[WPF] SelectionChanged of a child ListBox
- by quimbs
Hi,
I have a ListBox bound to an ObservableCollection with an ItemTemplate that contains another ListBox. First of all, I tried to get the last selected item of all the listboxes (either the parent and the inner ones) from my MainWindowViewModel this way:
public object SelectedItem
{
get { return this.selectedItem; }
set
{
this.selectedItem = value;
base.NotifyPropertyChanged("SelectedItem");
}
}
So, for example, in the DataTemplate of the items of the parent ListBox I've got this:
<ListBox ItemsSource="{Binding Tails}"
SelectedItem="{Binding Path=DataContext.SelectedItem, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}"/>
The problem now, is that when I select an item from the parent ListBox and then an item from a child listbox, I get this:
http://i40.tinypic.com/j7bvig.jpg
As you can see, two items are selected at the same time. How can I solve that?
Thanks in advance.