Opening the context menu just above the item in the application for the application win 8

I have a list of items defined in a ListView. When the user clicks or clicks on any item, I want to show PopupMenu just above the selected item. How do I put PopupMenu?

varmenu =newPopupMenu();
menu.Commands.Add(
newUICommand("Remove", (x) =>
{...
// Create the message dialog and set its content
}, 1));

var chosenCommand     =awaitmenu.ShowForSelectionAsync(GetElementRect((FrameworkElement)sender));

Rect GetElementRect(FrameworkElement element)
{    
    GeneralTransform buttonTransform = element.TransformToVisual(null);
    Pointpoint = buttonTransform.TransformPoint(newPoint());
    returnnewRect(point,newSize(element.ActualWidth, element.ActualHeight));
}
+3
source share
1 answer

This is the code I used to open the popup menu above the button in the application bar.

private async void OnOpenMenu(object sender, RoutedEventArgs e)
{
    var button = (Button)sender;
    var transform = button.TransformToVisual(this);
    var point = transform.TransformPoint(new Point(0, 0));

    var menu = new PopupMenu();

    menu.Commands.Add(new UICommand("Menu Item 1"));
    menu.Commands.Add(new UICommand("Menu Item 2"));

    await menu.ShowAsync(point);
}
+3
source

All Articles