FieldList ContextMenuBehavior
All of the context menus that appear in the PivotFieldList are generated by its FieldListContextMenuBehavior. The PivotFieldList provides the option to inherit and modify its default FieldListContextMenuBehavior in order to implement custom context menu functionality by adding or removing MenuItems.
Implementing a custom FieldListContextMenuBehavior
In this article it will be demonstrated how to implement a custom FieldListContextMenuBehavior and modify the context menu for the PropertyGroupDescription items. First thing you have to do is to create a custom class which inherits from the default FieldListContextMenuBehavior. Then you will need to simply override the virtual CreateContextMenu method. Inside of that method you can get the default context menu by calling the base method. So until this point your class should look like as shown below:
Having the default context menu will allow you to modify it as needed, for example you will be able to remove MenuItems from there or add new ones and attach custom commands to them. Let's imagine that you just need to remove the MenuItem for the Label Filter options and add a new one which is just showing a MessageBox. This should be done the following way:
The final step is to set the custom behavior to the PivotFieldList the follow way:
The custom behavior can be also set in the code behind as shown below:
And this will be the final result:
You can use exactly the same approach in order to modify the context menu of the other description types. You will need to check whether the dataContext object is a type of the desired group descripton (for example DoubleGroupDescription or AggregateDescriptionBase) and implement the required functionality.
Find a runnable project of the previous example in the WPF Samples GitHub repository.