Reputation: 1
I need a context menu with items: Delete Row, Insert Row
I need to show these context menu items in different grids. However the behavior of these options is based on selected grid data source.
Is there any generic approach to fix this issue, without breaking the MVVM?
What I am doing is : Creating a custom context menu and exposing the dependency properties for each context menu item. So, that they can be binded individually in each grid.
Do we have any other approach to fix this?
Upvotes: 0
Views: 340
Reputation: 8791
The answer is 42.
Joke!!!
Since you have not posted any code I will post some.
This is how you create ContextMenu for cells.
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text={Binding}>
<TextBlock.ContextMenu>
<ContextMenu>
<MenuItem Header="Copy"/>
<MenuItem Header="Paste"/>
<MenuItem Header="Clear"/>
</ContextMenu>
</TextBlock.ContextMenu>
</TextBlock>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
You can configure each MenuItem however you want e.g. to attach a dependency property on each MenuItem or to fire attached events from each item or you subscribe to click event.
Upvotes: 1