Skip to content

Commit 84e30d9

Browse files
authored
Update Sample to include MenuFlyout Invocation at Cursor Position (#6835)
* update test page with cursor positioned menu flyout * changes from comments
1 parent 86bd437 commit 84e30d9

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

dev/CommonStyles/TestUI/MenuFlyoutPage.xaml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,25 @@
99
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
1010
mc:Ignorable="d">
1111

12-
<Grid Margin="12">
12+
<local:TestPage.Resources>
13+
<MenuFlyout x:Key="SampleContextMenu">
14+
<MenuFlyoutItem Text="MenuFlyoutItem"/>
15+
<MenuFlyoutSubItem Text="MenuFlyoutSubItem">
16+
<MenuFlyoutItem Text="MenuFlyoutItem" />
17+
<ToggleMenuFlyoutItem Text="ToggleMenuFlyoutItem" />
18+
<MenuFlyoutSubItem Text="MenuFlyoutSubItem">
19+
<MenuFlyoutItem Text="MenuFlyoutItem" />
20+
<MenuFlyoutSeparator/>
21+
<MenuFlyoutItem Text="MenuFlyoutItem" />
22+
</MenuFlyoutSubItem>
23+
</MenuFlyoutSubItem>
24+
<MenuFlyoutSeparator/>
25+
<MenuFlyoutItem Text="MenuFlyoutItem"/>
26+
</MenuFlyout>
27+
</local:TestPage.Resources>
28+
29+
<Grid Margin="12" ContextRequested="Grid_ContextRequested">
30+
1331
<Grid.Background>
1432
<LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
1533
<GradientStop Color="Red" Offset="0.000" />
@@ -35,6 +53,8 @@
3553
</Grid.RowDefinitions>
3654

3755
<StackPanel Grid.RowSpan="2">
56+
<TextBlock Text="Right-click grid to invoke MenuFlyout from cursor position" Margin="0,0,0,12"/>
57+
3858
<Button Content="Short Text MenuFlyout" x:Name="TestMenuFlyoutButton" AutomationProperties.Name="TestMenuFlyoutButton" Margin="0,0,0,12">
3959
<Button.Flyout>
4060
<MenuFlyout>

dev/CommonStyles/TestUI/MenuFlyoutPage.xaml.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

4+
using Windows.Foundation;
45
using Windows.Foundation.Metadata;
56
using Windows.UI.Xaml;
67
using Windows.UI.Xaml.Controls;
@@ -12,15 +13,32 @@ namespace MUXControlsTestApp
1213
[TopLevelTestPage(Name = "MenuFlyout", Icon = "MenuFlyout.png")]
1314
public sealed partial class MenuFlyoutPage : TestPage
1415
{
16+
private MenuFlyout sharedFlyout;
1517
public MenuFlyoutPage()
1618
{
1719
this.InitializeComponent();
20+
21+
sharedFlyout = (MenuFlyout)Resources["SampleContextMenu"];
1822
}
1923

2024
private void TestMenuFlyoutItemClick(object sender, object e)
2125
{
2226
TestMenuFlyoutItemHeightTextBlock.Text = $"{TestMenuFlyoutItem.ActualHeight}";
2327
TestMenuFlyoutItemWidthTextBlock.Text = $"{TestMenuFlyoutItem.ActualWidth}";
2428
}
29+
30+
private void Grid_ContextRequested(UIElement sender, ContextRequestedEventArgs args)
31+
{
32+
var requestedElement = sender as FrameworkElement;
33+
34+
if (args.TryGetPosition(requestedElement, out Point point))
35+
{
36+
sharedFlyout.ShowAt(requestedElement, point);
37+
}
38+
else
39+
{
40+
sharedFlyout.ShowAt(requestedElement);
41+
}
42+
}
2543
}
2644
}

0 commit comments

Comments
 (0)