I have two lists with different ItemsSource
but with SelectedItem
bound to the same property - "Name".
First i'm choosing the item "c" in the right list so the item "c" in the left list is selected as well.
Than I selected another item in the right list but the "c" in the left list is still selected. I understand why it do that, but can I make it unselect the "c" in the right list ?
XAML:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<ListView SelectedItem="{Binding Name}" ItemsSource="{Binding lstNames1}"/>
<ListView SelectedItem="{Binding Name}" ItemsSource="{Binding lstNames2}" Grid.Column="1"/>
</Grid>
Code behind:
public partial class selected : Window
{
public ObservableCollection<string> lstNames1 { get; set; }
public ObservableCollection<string> lstNames2 { get; set; }
public string Name { get; set; }
public selected()
{
Names1 = new ObservableCollection<string> {"a1", "b1", "c"};
Names2 = new ObservableCollection<string> { "a2", "b2", "c" };
InitializeComponent();
DataContext = this;
}
}
If you switch the SelectedItem
binding to SelectedValue
this will behave how you want, The SelectedItem
is not clearing because its not set to null
because the other list has set a value, SelectedValue
acts a bit differntly as it has to find an item or it will clear the SelectedItem
on the list.
<ListView SelectedValue="{Binding Name}" ItemsSource="{Binding lstNames1}" />
<ListView SelectedValue="{Binding Name}" ItemsSource="{Binding lstNames2}" Grid.Column="1"/>
Hope that make sense :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With