XAML ContextMenu

ContextMenu element represents a context menu in XAML. This article shows you how to use ContextMenu element to create context menus in XAML.
  • 2310

This article explains how to use XAML <ContextMenu> element to create context menus.

We can attach a ContextMenu to any WPF/XAML control by using its ContextMenu property.

The following code snippet creates a Button and a ContextMenu control and attaches the ContextMenu to a Button using Button.ContextMenu property.

Button Name="CM1" Height="30" Width="200"  >
  Button Context Menu
  <Button.ContextMenu>
    <ContextMenu Name="ContextMenu1" >
      <MenuItem Header="File"/>
      <MenuItem Header="Save"/>
      <MenuItem Header="SaveAs"/>
    </ContextMenu>
  </Button.ContextMenu>
</Button>
 
Further Readings

You may also want to read these related articles.

Ask Your Question 

Got a programming related question? You may want to post your question here
© 2013 dotNetheaven. All rights reserved.