Possible Duplicate:
Adding different context menu for datagrid’s header
I have datagrid, but in context menu I want to see my own fields(not开发者_C百科 Copy Cut Paste) Can anybody help me to do this,please&
You can do this with an implicit style. In your controls resources add the following:
<Style
TargetType="{x:Type dg:DataGridCell}">
<Setter
Property="ContextMenu">
<Setter.Value>
<ContextMenu>
<MenuItem Header="First One" />
<MenuItem Header="Second One" />
</ContextMneu>
</Setter.Value>
</Setter>
</Style>
Note: If you want this to be on say a TextBox (because that is what you are showing in Edit mode) just change the TargetType line to be {x:Type TextBox} or whatever other control you want.
post some source code please. this works for me:
<DataGrid>
<DataGrid.ContextMenu>
<!-- your menu stuff goes here -->
<DataGrid.ContextMenu>
</DataGrid>
精彩评论