Disable / Enable context menu item depending on the list item
I have UserControl
c ListView
. Also, I have a listViewItems.cs class with DisplayMemberBinding for GridView
in ListView
.
Each ListView item has a context menu. Now I am trying to enable / disable context menu items if the value in the ListViewItems class isnull
I have tried binding a property IsEnabled
to a boolean ShowResItemEn
in the ListViewItems.cs class but it doesn't work.
DataOutput.xaml
<ListView.Resources>
<ContextMenu x:Name="cmListView" x:Key="ItemContextMenu" DataContext="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}}}">
<MenuItem x:Name="itmRes"
Header="Reservierungen anzeigen"
IsEnabled="{Binding PlacementTarget.SelectedItem.ShowResItemEn, RelativeSource={RelativeSource FindAncestor,AncestorType=ContextMenu}}"
Command="{Binding ShowResItemCmd}"
CommandParameter="{Binding RelativeSource={RelativeSource AncestorType=ContextMenu}, Path=PlacementTarget.SelectedItem}" >
</MenuItem>
</ContextMenu>
</ListView.Resources>
ListViewItems.cs class
public Boolean ShowResItemEn
{
get
{
return (auftrNr[0] == null) ? false : true;
}
}
+3
source to share