Code Reference A collection of code for my reference (and perhaps other people too)

28May/100

Simpel context menues in WPF

The first thin you must do is to create the context menu in the xaml page.
This is done as follows:

<UserControl.ContextMenu>
    <ContextMenu Name="rightClickContextMenu" Visibility="Collapsed">
        <MenuItem Header="Delete" Name="btnDelete" Click="btnDelete_Click"/>
        <MenuItem Header="Open" Name="btnOpen" Click="btnOpen_Click"/>
        <MenuItem Header="Copy" Name="btnCopy" Click="btnCopy_Click"/>
    </ContextMenu>
</UserControl.ContextMenu>

Listen for the right click event and display the menu

private void m(object sender, MouseEventArgs e)
{
    if (e.RightButton == MouseButtonState.Pressed)
    {

        rightClickContextMenu.PlacementRectangle = new Rect(e.GetPosition(diagram), new Size());
        rightClickContextMenu.Visibility = Visibility.Visible;
    }
}
Tagged as: Leave a comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment

No trackbacks yet.