Can't clear ListBox selection using SelectedItem = null - MVVM
Forget SelectedItem and SelectedIndex. The answer is SelectedValue, along with IsSynchronizedWithCurrentItem="True".
<ListBox IsSynchronizedWithCurrentItem="True" SelectedValue="{Binding SelectedSnapshotValue}" .../>
Then, when I call ResetSelection() in the view model, SelectedSnapshotValue is set to null,
void ResetSelection(){ SelectedSnapshotValue = null;}
which updates the binding in the data template, using the bound property:
private SnapshotViewModel selectedSnapshotValue; public SnapshotViewModel SelectedSnapshotValue { get { return selectedSnapshotValue; } set { if (selectedSnapshotValue != value) { selectedSnapshotValue = value; RaisePropertyChanged("SelectedSnapshotValue"); } } }
This is the only way I was able to get my listbox to reset the selection.