Hello.
How can I prevent the context menu from appearing based on the index the user click on in xamdatagrid? I imagine that I would use a data trigger but how do I get the right-clicked on record's index in xaml?
<ContextMenu.Style> <Style TargetType="{x:Type ContextMenu}"> <Style.Triggers> <DataTrigger Binding="{Binding Path=PlacementTarget.Record}" Value="-1"> <Setter Property="Visibility" Value="Hidden"/> </DataTrigger> </Style.Triggers> </Style> </ContextMenu.Style>
Hello and thanks for your suggestion
I was able to make it hide with the below code. Rather than using the index I have another property that tells me whether the row is disabled which I took advantage of.
<Style TargetType="{x:Type igWPF:CellValuePresenter}"> <Style.Triggers> <DataTrigger Binding="{Binding Path=DataItem.IsRowDisabled}" Value="True"> <Setter Property="ContextMenu"> <Setter.Value> <ContextMenu IsEnabled="False" Visibility="Hidden" /> </Setter.Value> </Setter> </DataTrigger> </Style.Triggers>
</Style>
Hello KrisVice,
Just checking in, did you have any other questions or concerns on this matter?
Sincerely,AndrewAssociate DeveloperInfragistics Inc.www.infragistics.com/support
Thank you for your post.
To get a context menu on the records of a XamDataGrid to not show up based on the index of the record, I would recommend writing a Style for DataRecordPresenter. In that style, you can set the context menu property to your context menu, and write a Style for it with the trigger that you have provided. One difference though, is that you will want to change the binding on the DataTrigger to be like the following, otherwise you are binding to the data context of the context menu:
{Binding RelativeSource={RelativeSource Self}, Path=PlacementTarget.Record.Index}.
Please let me know if you have any other questions or concerns on this matter.