![](/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.