Category / Section
How to bind the ItemSource for ContextMenu of SfdataGrid
1 min read
SfDataGrid allows you to set the ContextMenus for Headers, Records, GroupCaption, GroupDropArea, GroupDropItem, GroupSummary, and TableSummary. Menu collections are bounded as ItemSource for ContextMenu with the ItemSource property binding. Refer the following code sample,
XAML
<Window.Resources> <local:ViewModel x:Key="ViewModel" /> </Window.Resources> <Syncfusion:SfDataGrid.HeaderContextMenu> <ContextMenu ItemsSource="{Binding MenuList, Source={StaticResource ViewModel}}" /> </Syncfusion:SfDataGrid.HeaderContextMenu>
Here, MenuList property can be accessed from ViewModel by setting StaticResource. ContextMenu for Header is set using SfDataGrid.HeaderContextMenu. Similarly ContextMenu can be set for Records, GroupCaption, GroupDropArea, GroupDropItem, GroupSummary, and TableSummary.
The following screenshot shows the ContextMenu of Header,
You can refer to the sample from the following location.
Sample Link: WPF