Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
225
Xamdatagrid Context menu visibility
posted

I am working on Xamdatagrid with WPF MVVM pattern. I am displaying context menu on right click event on row of grid. Could we restrict the Context menu visibility on some row depending on certain condition. e.g. If I  right clicked on a one row it should display context menu and if I right clicked on second row it should not.

Here is the code

 <ContextMenu x:Key="RecordContextMenu" Visibility="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type igDP:XamDataGrid}}, Path=DataContext.ContextMenuVisibility, Converter={StaticResource BoolVisibilityConverter},Mode=TwoWay}">
                <ContextMenu.Resources>
                    <Converters:BoolVisibilityConverter x:Key="BoolVisibilityConverter" />
                </ContextMenu.Resources>
                <MenuItem Name="SendTo" Header="Send To"
                    Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type igDP:XamDataGrid}}, Path=DataContext.SendCommand}"
                    CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type igDP:XamDataGrid}},Path=ActiveRecord}">                   
                </MenuItem>
            </ContextMenu>
            <Style TargetType="{x:Type igDP:DataRecordCellArea}">
                <Setter Property="ContextMenu" Value="{DynamicResource RecordContextMenu}"></Setter>
            </Style>
        </igDP:XamDataGrid.Resources>