I am using a Listbox in m WPF app where I tried to remove the SelectedItem so the user can reclick on it to do an action.
I have a classic ListBox :
<ListBox
x:Name="MenuItemList"
Grid.Row="1"
IsSynchronizedWithCurrentItem="True"
ItemsSource="{Binding MenuItems}"
SelectedItem="{Binding SelectedMenu, UpdateSourceTrigger=PropertyChanged}">
[...] </ListBox>
I have binded the SelectedMenu in my VM :
public MenuItem SelectedMenu
{
get { return null; }
set
{
MenuIsOpened = false;
DisplayedMenu = value;
OnPropertyChanged("SelectedMenu");
}
}
I tried another way with a private property where I changed it to null
private MenuItem _SelectedMenu;
public MenuItem SelectedMenu
{
get { return _SelectedMenu; }
set
{
MenuIsOpened = false;
DisplayedMenu = value;
_SelectedMenu = null;
OnPropertyChanged("SelectedMenu");
}
}
But it does not work as I want... When I click on an item, the property is null but in the view, the listbox always highlights the selected item and the second click on it doesn't trigger the property.