Skip to content

Update Sample to include MenuFlyout Invocation at Cursor Position #6835

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion dev/CommonStyles/TestUI/MenuFlyoutPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,25 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<Grid Margin="12">
<local:TestPage.Resources>
<MenuFlyout x:Key="SampleContextMenu">
<MenuFlyoutItem Text="MenuFlyoutItem"/>
<MenuFlyoutSubItem Text="MenuFlyoutSubItem">
<MenuFlyoutItem Text="MenuFlyoutItem" />
<ToggleMenuFlyoutItem Text="ToggleMenuFlyoutItem" />
<MenuFlyoutSubItem Text="MenuFlyoutSubItem">
<MenuFlyoutItem Text="MenuFlyoutItem" />
<MenuFlyoutSeparator/>
<MenuFlyoutItem Text="MenuFlyoutItem" />
</MenuFlyoutSubItem>
</MenuFlyoutSubItem>
<MenuFlyoutSeparator/>
<MenuFlyoutItem Text="MenuFlyoutItem"/>
</MenuFlyout>
</local:TestPage.Resources>

<Grid Margin="12" ContextRequested="Grid_ContextRequested">

<Grid.Background>
<LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
<GradientStop Color="Red" Offset="0.000" />
Expand All @@ -35,6 +53,8 @@
</Grid.RowDefinitions>

<StackPanel Grid.RowSpan="2">
<TextBlock Text="Right-click grid to invoke MenuFlyout from cursor position" Margin="0,0,0,12"/>

<Button Content="Short Text MenuFlyout" x:Name="TestMenuFlyoutButton" AutomationProperties.Name="TestMenuFlyoutButton" Margin="0,0,0,12">
<Button.Flyout>
<MenuFlyout>
Expand Down
18 changes: 18 additions & 0 deletions dev/CommonStyles/TestUI/MenuFlyoutPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using Windows.Foundation;
using Windows.Foundation.Metadata;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
Expand All @@ -12,15 +13,32 @@ namespace MUXControlsTestApp
[TopLevelTestPage(Name = "MenuFlyout", Icon = "MenuFlyout.png")]
public sealed partial class MenuFlyoutPage : TestPage
{
private MenuFlyout sharedFlyout;
public MenuFlyoutPage()
{
this.InitializeComponent();

sharedFlyout = (MenuFlyout)Resources["SampleContextMenu"];
}

private void TestMenuFlyoutItemClick(object sender, object e)
{
TestMenuFlyoutItemHeightTextBlock.Text = $"{TestMenuFlyoutItem.ActualHeight}";
TestMenuFlyoutItemWidthTextBlock.Text = $"{TestMenuFlyoutItem.ActualWidth}";
}

private void Grid_ContextRequested(UIElement sender, ContextRequestedEventArgs args)
{
var requestedElement = sender as FrameworkElement;

if (args.TryGetPosition(requestedElement, out Point point))
{
sharedFlyout.ShowAt(requestedElement, point);
}
else
{
sharedFlyout.ShowAt(requestedElement);
}
}
}
}