/// <summary> 确定点击的控件所在的位置
/// 确定点击的控件所在的位置
/// </summary>
/// <param name="sender">被点击的控件</param>
/// <returns>sender所在位置</returns>
private Rect GetRect(object sender)
{
FrameworkElement element = sender as FrameworkElement;
GeneralTransform elementTransform = element.TransformToVisual(null);
Point point = elementTransform.TransformPoint(new Point());
return new Rect(point, new Size(element.ActualWidth, element.ActualHeight));
}
/// <summary> 右键单击Button 在button的右侧显示菜单项
/// 右键单击Button 在button的右侧显示菜单项
/// </summary>
/// <param name="sender">Button控件</param>
/// <param name="e"></param>
private async void Button_RightTapped_1(object sender, RightTappedRoutedEventArgs e)
{
Windows.UI.Popups.PopupMenu popupmenu = new Windows.UI.Popups.PopupMenu();
popupmenu.Commands.Add(new Windows.UI.Popups.UICommand("one", c => { }));
popupmenu.Commands.Add(new Windows.UI.Popups.UICommand("two", c => { }));
popupmenu.Commands.Add(new Windows.UI.Popups.UICommandSeparator()); // 分隔符
popupmenu.Commands.Add(new Windows.UI.Popups.UICommand("three", c => { }));
await popupmenu.ShowForSelectionAsync(GetRect(sender), Windows.UI.Popups.Placement.Right);
}
![](https://img-my.csdn.net/uploads/201212/22/1356142967_5223.png)