I have a ContextMenu
on a DataGrid
and I want to mark a MenuItem
as checked or unchecked depending on the item in the grid which is right-clicked.
So, I bind the 'IsChecked' property on the MenuItem
to a property on my ViewModel, and this property is set to true or false by my VM according to item that is right-clicked.
However, turns out that 'IsChecked' property of my ContextMenu
Item is evaluated only once. It is not evaluated everytime I rightclick an item.
For all subsequent right-clicks, the evaluation carried out the first time is retained.
The getter for property 'IsCheckedonVM' is not fired.
<MenuItem Command= IsCheckable="True"
IsChecked="{Binding IsCheckedonVM}"
Header = ".."
</MenuItem>
in the VM:
public bool IsCheckedonVM
{
get
{
return selectedItem.IsChecked;
}
set
{
selecteditem.IsChecked = value;
OnPropertyChanged("IsCheckedonVM");
}
How can I get the IsChecked
property on my MenuItem
to be evaluated everytime its rightclicked, so that IsCheckedonVM
is fetched everytime?