forum

Home / DeveloperSection / Forums / Get owner of context menu on Button

Get owner of context menu on Button

Jayden Bell 2112 16-Aug-2013
Hi Developers!

Title just about says it all.I have a lot of buttons, all of them have the same context menu, I want to determine from the click event which button was rgiht clicked to get there.

This code does not work, placementTarget is null:

private void mi_Click(object sender, RoutedEventArgs e)
{
        Button contextMenuEzen = null;
        MenuItem mnu = sender as MenuItem;
        if (mnu != null)
        {
            ContextMenu ize =(ContextMenu)mnu.Parent;
            contextMenuEzen = ize.PlacementTarget as Button;
        }
}

Please help me!



wpf wpf 
Updated on 17-Aug-2013

Can you answer this question?


Answer

1 Answers

Liked By