Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/303.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
C# 菜单当原点更改时不出现上升事件_C#_Uwp - Fatal编程技术网

C# 菜单当原点更改时不出现上升事件

C# 菜单当原点更改时不出现上升事件,c#,uwp,C#,Uwp,我有一个代码,它在应用程序的特定位置显示了一个MenuFlyout(用户在控件上点击了rightstapped)。当我将菜单Out与 f.ShowAt(发送方作为框架元素) 但它的位置不在必须显示的位置附近(发送器控件在屏幕上相当大) 因此,我将showing命令更改为 f.ShowAt(发送方作为框架元素,参数位置)。 现在,MenuFlyout显示在它应该在的位置(就在RightTap位置的顶部),但它不会对项目上的点击事件做出反应MenuFlyout隐藏项目,但项目上没有事件 MenuFl

我有一个代码,它在应用程序的特定位置显示了一个
MenuFlyout
(用户在控件上点击了
rightstapped
)。当我将
菜单Out
f.ShowAt(发送方作为框架元素)
但它的位置不在必须显示的位置附近(发送器控件在屏幕上相当大)

因此,我将showing命令更改为
f.ShowAt(发送方作为框架元素,参数位置)
。 现在,
MenuFlyout
显示在它应该在的位置(就在
RightTap
位置的顶部),但它不会对项目上的点击事件做出反应
MenuFlyout
隐藏项目,但项目上没有事件

MenuFlyout f = new MenuFlyout();
MenuFlyoutItem menuFlyoutItem = new MenuFlyoutItem
{
    Text      = "Open in X1",
    IsTabStop = false,    
    Tag       = args.Location
};
menuFlyoutItem.AddHandler(TappedEvent, new TappedEventHandler(OpenInX1_Tapped), true);
f.Items.Add(menuFlyoutItem);
menuFlyoutItem = new MenuFlyoutItem
{
    Text      = "Open in X2",
    IsTabStop = false,
    Tag       = args.Location
};
menuFlyoutItem.AddHandler(TappedEvent, new TappedEventHandler(OpenInX2_Tapped), true);
f.Items.Add(menuFlyoutItem);
f.Placement = FlyoutPlacementMode.Top;
f.ShowAt(sender as FrameworkElement, args.Position);
//f.ShowAt(sender as FrameworkElement);
你知道为什么会这样吗?还有,我怎样才能修复它

多谢各位

但它不会对项目上的点击事件做出反应。MenuFlyout隐藏,但在项目上没有事件

MenuFlyout f = new MenuFlyout();
MenuFlyoutItem menuFlyoutItem = new MenuFlyoutItem
{
    Text      = "Open in X1",
    IsTabStop = false,    
    Tag       = args.Location
};
menuFlyoutItem.AddHandler(TappedEvent, new TappedEventHandler(OpenInX1_Tapped), true);
f.Items.Add(menuFlyoutItem);
menuFlyoutItem = new MenuFlyoutItem
{
    Text      = "Open in X2",
    IsTabStop = false,
    Tag       = args.Location
};
menuFlyoutItem.AddHandler(TappedEvent, new TappedEventHandler(OpenInX2_Tapped), true);
f.Items.Add(menuFlyoutItem);
f.Placement = FlyoutPlacementMode.Top;
f.ShowAt(sender as FrameworkElement, args.Position);
//f.ShowAt(sender as FrameworkElement);
请参阅本文档

这是一个路由事件。此外,元素必须为true才能作为抽头事件源(默认为true)。即使父元素上的IsTapEnabled为false,也可以处理父元素上的点击

这将使菜单显示一次又一次。对于这个场景,更好的方法是listen
MenuFlyoutItem
event,它将在任何时候调用

 MenuFlyoutItem menuFlyoutItem = new MenuFlyoutItem
 {
     Text = "Open in X1",
     IsTabStop = false,

 };
 menuFlyoutItem.Click += new RoutedEventHandler(MenuFlyoutItem_Click1);
 f.Items.Add(menuFlyoutItem);

改变了的方法奏效了。但是仍然不知道为什么在f.ShowAt上添加args.position(发送方作为FrameworkElement,args.position);这种影响。