你可以使用Flyout.ShowAtshow it,但你应该给出一个位置。
尝试RightTapped="GridColection_OnRightTapped"在 DataTemplate 中使用。或者您使用按钮单击。
在GridCollection_OnRightTapped中,可以使用e.GetPosition来获取位置。
如果你想从UIElement获取位置,你可以使用代码获取屏幕坐标:
var t = UIElement.TransformToVisual(Window.Current.Content);
Point screenCoords = t.TransformPoint(new Point(0, 0));
Run Code Online (Sandbox Code Playgroud)
UIElement 是您的 GridViewItem。
在代码中:
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));
}
Run Code Online (Sandbox Code Playgroud)

请参阅:如何获取元素的绝对位置?
| 归档时间: |
|
| 查看次数: |
2436 次 |
| 最近记录: |