Flyout.ShowAt
がそれを示していますが、位置を与える必要があります。
DataTemplateでRightTapped="GridColection_OnRightTapped"
を試してみてください。または、ボタンのクリックを使用します。
GridColection_OnRightTappedでは、e.GetPosition
を使用して位置を取得できます。
あなたがUIElementから位置を取得したい場合は、画面のCOORDSを取得するためのコードを使用することができます:
var t = UIElement.TransformToVisual(Window.Current.Content);
Point screenCoords = t.TransformPoint(new Point(0, 0));
の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));
}
を参照してください:あなたは中国を読み取ることができる場合は、WebBlogとthisを参照してください。How to get the absolute position of an element?
。
私はFlyFutではなくMenuFlyoutを持っています。 MenuFlyoutには、位置を取るメソッドShowAtがありません。それはすべて私の問題です –
@mister_gigaこれは私の誤解です – lindexi