Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding different context menu for datagrid's header

Tags:

c#

.net

wpf

I want to add a different context menu for my datagrid's header on WPF. How can I do that?

like image 209
Thiago Avatar asked Oct 19 '25 13:10

Thiago


1 Answers

These resources will help you on the way:

  • Context Menus in WPF
  • WPF Context Menus
  • How to create Custom WPF Context Menus

WPF used XAML which is another Markup Language and one common thing that you usualy see is that tags are reused on a lot of controls. In the examples above you can see that controls like

  • RichTextBox
  • Data Grid
  • And many more..

Has the Control.ContextMenuwhere you can creat your specific menu for that item. Taken from the first link above, see this example on RichTextBox

<RichTextBox>
    <RichTextBox.ContextMenu>
        <ContextMenu>
        </ContextMenu>
    </RichTextBox.ContextMenu> 
</RichTextBox>

And this doesn't apply only to the ContextMenu! There are other reusable elements like this. Depending on what DataGrid you are using, you have to look into the API for that but it is most likely working its ways like this.

like image 52
Filip Ekberg Avatar answered Oct 22 '25 04:10

Filip Ekberg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!