![](/img/trans.png)
[英]ContextMenuStrip On RightClick, IF Items Are Selected In Listview?
[英]RightClick menu on ListView UWP
我有一个通过鼠标右键调用上下文菜单的代码。
private void GridColections_RightTapped(object sender, RightTappedRoutedEventArgs e)
{
MenuFlyout myFlyout = new MenuFlyout();
MenuFlyoutItem firstItem = new MenuFlyoutItem { Text = "OneIt" };
MenuFlyoutItem secondItem = new MenuFlyoutItem { Text = "TwoIt" };
myFlyout.Items.Add(firstItem);
myFlyout.Items.Add(secondItem);
FrameworkElement senderElement = sender as FrameworkElement;
myFlyout.ShowAt(senderElement);
}
但是菜单出现在我的列表视图的中心。 不在我单击鼠标的地方。 如何解决?
如果要在鼠标单击点显示ShowAt(UIElement,Point)
显示,则可以使用ShowAt(UIElement,Point)
而不是ShowAt(FrameworkElement)
。
可以在点击点显示弹出按钮的代码。
private void GridColection_OnRightTapped(object sender, RightTappedRoutedEventArgs e)
{
MenuFlyout myFlyout = new MenuFlyout();
MenuFlyoutItem firstItem = new MenuFlyoutItem { Text = "OneIt" };
MenuFlyoutItem secondItem = new MenuFlyoutItem { Text = "TwoIt" };
myFlyout.Items.Add(firstItem);
myFlyout.Items.Add(secondItem);
//if you only want to show in left or buttom
//myFlyout.Placement = FlyoutPlacementMode.Left;
FrameworkElement senderElement = sender as FrameworkElement;
//the code can show the flyout in your mouse click
myFlyout.ShowAt(sender as UIElement, e.GetPosition(sender as UIElement));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.