This is one way around this. It is a bit dirty, but it works.
First create an IValueConverter to say that 1 means enable (true), and Value Converter might look like this:
public class OneReturnsTrueConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { return (int)value == 1; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotSupportedException(); } }
Then save the link to the DataGrid in the DataGridRow
<DataGrid.RowStyle > <Style TargetType="{x:Type DataGridRow}"> <Setter Property="Tag" Value="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGrid}}}" /> <Setter Property="ContextMenu" Value="{StaticResource DataRowContextMenu}" /> <Setter Property="BorderThickness" Value="0"/> </Style> </DataGrid.RowStyle>
And finally, bind the SelectedItems value of the grid to the IsEnabled property
<DataGrid.Resources> <myConverters:OneReturnsTrueConverter x:Key="OneReturnsTrueConverter"/> <ContextMenu x:Key="DataRowContextMenu"> <MenuItem x:Name="RowContMenuProp" Header="Properties" DataContext="{Binding Parent.PlacementTarget.Tag , RelativeSource={RelativeSource Self}}" IsEnabled="{Binding Path=SelectedItems.Count, Converter={StaticResource OneReturnsTrueConverter}}" /> </ContextMenu> </DataGrid.Resources>
source share