开发者

contextmenu datagrid wpf [duplicate]

开发者 https://www.devze.com 2023-03-02 22:21 出处:网络
This question already has answers here: Closed 10 years ago. Possible Duplicate: Adding different context menu for datagrid’s header
This question already has answers here: Closed 10 years ago.

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>
0

精彩评论

暂无评论...
验证码 换一张
取 消