C# 在特定位置的UI元素上方显示弹出按钮

C# 在特定位置的UI元素上方显示弹出按钮,c#,xaml,gridview,popup,uwp,C#,Xaml,Gridview,Popup,Uwp,我有gridView,它的项目非常简单,每个gridView项目上都有按钮。在此按钮上单击“我想显示一个弹出型按钮,该弹出型按钮的内容与gridViewItem相同,但也要显示更多数据”。这很简单,但我想将弹出按钮放置在gridViewItem上方,使其显示的项目与gridViewItem项目的位置完全相同 此技术用于Windows 10的应用商店应用程序。当看到用户对应用程序的评论时。单击“更多”将显示该弹出窗口 您可以使用弹出按钮。ShowAt显示它,但您应该给出一个位置 尝试在DataTe

我有gridView,它的项目非常简单,每个gridView项目上都有按钮。在此按钮上单击“我想显示一个弹出型按钮,该弹出型按钮的内容与gridViewItem相同,但也要显示更多数据”。这很简单,但我想将弹出按钮放置在gridViewItem上方,使其显示的项目与gridViewItem项目的位置完全相同

此技术用于Windows 10的应用商店应用程序。当看到用户对应用程序的评论时。单击“更多”将显示该弹出窗口


您可以使用
弹出按钮。ShowAt
显示它,但您应该给出一个位置

尝试在DataTemplate中使用
RightTapped=“GridCollection\u OnRightTapped”
。或者你用按钮点击

在右侧点击的GridCollection_中,可以使用
e.GetPosition
获取位置

如果要从UIElement获取位置,可以使用代码获取屏幕坐标:

        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));
}

见:


如果你能读中文,请看和。

我有弹出菜单,而不是菜单。MenuFlyout没有占据位置的方法ShowAt。这就是我的全部problem@mister_giga这是我的误解