A useful extension method

Sep 21, 2011 at 5:13 AM

Saves me few lines of code every time I open it programmatically :)

public static PopupMenu Open(this PopupMenu menu, MouseButtonEventArgs args)
{
   args.Handled = true;
   menu.Open(args.GetPosition(null), true, true);
   return menu;
}

Used to be

title.MouseRightButtonDown += (_, args) => 
{
   GetPopupMenu().Open(args.GetPosition(null), true, true);
   args.Handled = true;
}

Now

title.MouseRightButtonDown += (_, args) => GetPopupMenu().Open(args);