OK, this should be a duplicate question, but I canβt find the answer: I have a list related to collection binding. By default, items [0] are selected. How can I prevent this from happening to ensure that the SelectionChanged event is raised every time I click the ListBoxItem button?
EDIT: I already rejected the SelectedIndex = -1 route, but I tried again: setting SelectedIndex to -1 in the Listbox constructor (or as an attribute in XAML) does not work. It seems that the listbox is populated after initialization, and selectedindex will become 0 after all. This story is for setting SelectedItem to null;
I tried this:
<ListBox ItemsSource="{Binding Value}"
SelectionChanged="ListBox_SelectionChanged"
IsSynchronizedWithCurrentItem="True"
Loaded="ListBox_Loaded">
</ListBox>
with:
private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if(e.AddedItems.Count==0)return;
((ListBox)e.OriginalSource).SelectedItem=null;
}
private void ListBox_Loaded(object sender, RoutedEventArgs e)
{
((ListBox) sender).SelectedItem = null;
}
, , , ....
, IsSynchronizedWithCurrentItem.
, .
: master-detail IsSynchronizedWithCurrentItem true, . , master-detail,