From d5fc365308ec8f8ce901acc9eae3fdbdd2840d3a Mon Sep 17 00:00:00 2001 From: Max Katz Date: Thu, 15 Jul 2021 10:01:59 -0400 Subject: [PATCH] Merge pull request #6059 from AvaloniaUI/context-request-keyboard Add ContextRequest event, use it to show ContextFlyout/ContextMenu, allow to open context using keyboard # Conflicts: # samples/ControlCatalog/Pages/ContextFlyoutPage.axaml # samples/ControlCatalog/Pages/ContextMenuPage.xaml # tests/Avalonia.Controls.UnitTests/ContextMenuTests.cs --- .../Pages/ContextFlyoutPage.axaml | 102 -------- .../Pages/ContextFlyoutPage.axaml.cs | 45 ---- .../Pages/ContextFlyoutPage.xaml | 157 ++++++++++++ .../Pages/ContextFlyoutPage.xaml.cs | 91 +++++++ .../ControlCatalog/Pages/ContextMenuPage.xaml | 139 +++++++---- .../Pages/ContextMenuPage.xaml.cs | 42 +++- .../ViewModels/ContextFlyoutPageViewModel.cs | 78 ------ ...geViewModel.cs => ContextPageViewModel.cs} | 4 +- src/Avalonia.Controls/ContextMenu.cs | 65 +++-- .../ContextRequestedEventArgs.cs | 58 +++++ src/Avalonia.Controls/Control.cs | 62 +++++ src/Avalonia.Controls/Flyouts/FlyoutBase.cs | 167 +++++++++---- .../Flyouts/FlyoutShowMode.cs | 2 +- .../Flyouts/MenuFlyoutPresenter.cs | 10 +- src/Avalonia.Controls/Primitives/Popup.cs | 10 + .../Platform/PlatformHotkeyConfiguration.cs | 15 +- src/Avalonia.Themes.Default/TextBox.xaml | 2 +- .../Controls/TextBox.xaml | 2 +- src/Windows/Avalonia.Win32/Win32Platform.cs | 9 +- .../ContextMenuTests.cs | 159 ++++++++++-- .../FlyoutTests.cs | 234 +++++++++++++++++- 21 files changed, 1058 insertions(+), 395 deletions(-) delete mode 100644 samples/ControlCatalog/Pages/ContextFlyoutPage.axaml delete mode 100644 samples/ControlCatalog/Pages/ContextFlyoutPage.axaml.cs create mode 100644 samples/ControlCatalog/Pages/ContextFlyoutPage.xaml create mode 100644 samples/ControlCatalog/Pages/ContextFlyoutPage.xaml.cs delete mode 100644 samples/ControlCatalog/ViewModels/ContextFlyoutPageViewModel.cs rename samples/ControlCatalog/ViewModels/{ContextMenuPageViewModel.cs => ContextPageViewModel.cs} (96%) create mode 100644 src/Avalonia.Controls/ContextRequestedEventArgs.cs diff --git a/samples/ControlCatalog/Pages/ContextFlyoutPage.axaml b/samples/ControlCatalog/Pages/ContextFlyoutPage.axaml deleted file mode 100644 index e15637aa0f..0000000000 --- a/samples/ControlCatalog/Pages/ContextFlyoutPage.axaml +++ /dev/null @@ -1,102 +0,0 @@ - - - - - - - Context Flyout - A right click Flyout that can be applied to any control. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/samples/ControlCatalog/Pages/ContextFlyoutPage.axaml.cs b/samples/ControlCatalog/Pages/ContextFlyoutPage.axaml.cs deleted file mode 100644 index e64d4a2cdd..0000000000 --- a/samples/ControlCatalog/Pages/ContextFlyoutPage.axaml.cs +++ /dev/null @@ -1,45 +0,0 @@ -using Avalonia; -using Avalonia.Controls; -using Avalonia.Markup.Xaml; -using ControlCatalog.ViewModels; -using Avalonia.Interactivity; -namespace ControlCatalog.Pages -{ - public class ContextFlyoutPage : UserControl - { - private TextBox _textBox; - - public ContextFlyoutPage() - { - InitializeComponent(); - - var vm = new ContextFlyoutPageViewModel(); - vm.View = this; - DataContext = vm; - - _textBox = this.FindControl("TextBox"); - - var cutButton = this.FindControl + + + + + + + + Hello world + + + Inner context flyout + + + + + + + diff --git a/samples/ControlCatalog/Pages/ContextFlyoutPage.xaml.cs b/samples/ControlCatalog/Pages/ContextFlyoutPage.xaml.cs new file mode 100644 index 0000000000..10f9ee1de8 --- /dev/null +++ b/samples/ControlCatalog/Pages/ContextFlyoutPage.xaml.cs @@ -0,0 +1,91 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Markup.Xaml; +using ControlCatalog.ViewModels; +using Avalonia.Interactivity; +using System; +using System.ComponentModel; + +namespace ControlCatalog.Pages +{ + public class ContextFlyoutPage : UserControl + { + private TextBox _textBox; + + public ContextFlyoutPage() + { + InitializeComponent(); + + DataContext = new ContextPageViewModel(); + + _textBox = this.FindControl("TextBox"); + + var cutButton = this.FindControl