Reputation: 161
I have this code that shows a MenuFlyout
on certain position of the app (where the user has RightTapped
on the control). Tap events on the items are risen Ok when I place the MenuFlyout
with
f.ShowAt(sender as FrameworkElement)
but it's position is not near where it must be shown (the sender control is quite big in the screen).
So, I changed the showing command to
f.ShowAt(sender as FrameworkElement, args.Position)
.
Now, the MenuFlyout
is shown where it should be (just on top of the RightTap
position), but it doesn't react to tap events on the items. MenuFlyout
hides but there's no event on items.
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);
Do you why is this happening? And, how could I fix it?
Thank you.
Upvotes: 1
Views: 56
Reputation: 32775
but it doesn't react to tap events on the items. MenuFlyout hides but there's no event on items.
Please refer this document Tapped
document
Tapped is a routed event. Also, an element must have IsTapEnabled be true to be a Tapped event source (true is the default). It is possible to handle Tapped on parent elements even if IsTapEnabled is false on the parent element,
That will make the menu show again and again. For this scenario, the better way is listen MenuFlyoutItem
Click event, it will invoke in any time.
MenuFlyoutItem menuFlyoutItem = new MenuFlyoutItem
{
Text = "Open in X1",
IsTabStop = false,
};
menuFlyoutItem.Click += new RoutedEventHandler(MenuFlyoutItem_Click1);
f.Items.Add(menuFlyoutItem);
Upvotes: 1