Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xaml windows 8中使用弹出菜单的上下文菜单_Xaml_Windows 8_Winrt Xaml - Fatal编程技术网

Xaml windows 8中使用弹出菜单的上下文菜单

Xaml windows 8中使用弹出菜单的上下文菜单,xaml,windows-8,winrt-xaml,Xaml,Windows 8,Winrt Xaml,嗨,我正在尝试使用弹出窗口在Windows8中创建上下文菜单。右击一个按钮,我调用以下函数 private async void UIElement_OnRightTapped(object sender, RightTappedRoutedEventArgs e) { PopupMenu popUpMenu = new PopupMenu(); popUpMenu.Commands.Add(new UICommand("File"));

嗨,我正在尝试使用弹出窗口在Windows8中创建上下文菜单。右击一个按钮,我调用以下函数

private async void UIElement_OnRightTapped(object sender, RightTappedRoutedEventArgs e)
    {
        PopupMenu popUpMenu = new PopupMenu();
        popUpMenu.Commands.Add(new UICommand("File"));
        Rect rect = GetRect(sender);
        var result= await popUpMenu.ShowForSelectionAsync(rect, Placement.Right);
    }
而GetRect方法的定义如下:-

private Rect GetRect(object sender)
    {
        FrameworkElement element = sender as FrameworkElement;
        GeneralTransform elementTransform = element.TransformToVisual(null);
        Point point = elementTransform.TransformPoint(new Point());
        Size size = new Size(element.ActualWidth, element.ActualHeight);
        Rect rect = new Rect(point, size);
        return rect;
    }
虽然GetRect返回正确的值,但我仍然将结果设置为null


请帮帮我,我不明白你为什么会有这样的问题。从第一个角度看,一切看起来都很好


也许Tim Heuer软件包包含了一种更简单的方法来满足您的需求。请参见示例。

这是因为您没有单击File命令,而是单击了页面上的其他位置。

我不知道为什么在未调试的情况下运行它时,效果很好