From 5265b0592a86b3e36df1e82d7e494518b5b7f1df Mon Sep 17 00:00:00 2001 From: Dariusz Komosinski Date: Thu, 29 Apr 2021 17:10:33 +0200 Subject: [PATCH 1/3] Implement MenuItem.StaysOpenOnClick. --- .../ControlCatalog/Pages/ContextMenuPage.xaml | 1 + src/Avalonia.Controls/IMenuItem.cs | 6 ++++++ src/Avalonia.Controls/MenuItem.cs | 16 ++++++++++++++++ .../Platform/DefaultMenuInteractionHandler.cs | 6 +++++- 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/samples/ControlCatalog/Pages/ContextMenuPage.xaml b/samples/ControlCatalog/Pages/ContextMenuPage.xaml index 260162ddb9..25f305151d 100644 --- a/samples/ControlCatalog/Pages/ContextMenuPage.xaml +++ b/samples/ControlCatalog/Pages/ContextMenuPage.xaml @@ -31,6 +31,7 @@ + diff --git a/src/Avalonia.Controls/IMenuItem.cs b/src/Avalonia.Controls/IMenuItem.cs index 94d761f725..d92625218a 100644 --- a/src/Avalonia.Controls/IMenuItem.cs +++ b/src/Avalonia.Controls/IMenuItem.cs @@ -23,6 +23,12 @@ namespace Avalonia.Controls /// bool IsSubMenuOpen { get; set; } + /// + /// Gets or sets a value that indicates the submenu that this is + /// within should not close when this item is clicked. + /// + bool StaysOpenOnClick { get; set; } + /// /// Gets a value that indicates whether the is a top-level main menu item. /// diff --git a/src/Avalonia.Controls/MenuItem.cs b/src/Avalonia.Controls/MenuItem.cs index 94099a970e..0995ce0e0b 100644 --- a/src/Avalonia.Controls/MenuItem.cs +++ b/src/Avalonia.Controls/MenuItem.cs @@ -69,6 +69,12 @@ namespace Avalonia.Controls public static readonly StyledProperty IsSubMenuOpenProperty = AvaloniaProperty.Register(nameof(IsSubMenuOpen)); + /// + /// Defines the property. + /// + public static readonly StyledProperty StaysOpenOnClickProperty = + AvaloniaProperty.Register(nameof(StaysOpenOnClick)); + /// /// Defines the event. /// @@ -265,6 +271,16 @@ namespace Avalonia.Controls set { SetValue(IsSubMenuOpenProperty, value); } } + /// + /// Gets or sets a value that indicates the submenu that this is + /// within should not close when this item is clicked. + /// + public bool StaysOpenOnClick + { + get { return GetValue(StaysOpenOnClickProperty); } + set { SetValue(StaysOpenOnClickProperty, value); } + } + /// /// Gets or sets a value that indicates whether the has a submenu. /// diff --git a/src/Avalonia.Controls/Platform/DefaultMenuInteractionHandler.cs b/src/Avalonia.Controls/Platform/DefaultMenuInteractionHandler.cs index e3e9e84d7e..984faa4d60 100644 --- a/src/Avalonia.Controls/Platform/DefaultMenuInteractionHandler.cs +++ b/src/Avalonia.Controls/Platform/DefaultMenuInteractionHandler.cs @@ -449,7 +449,11 @@ namespace Avalonia.Controls.Platform protected void Click(IMenuItem item) { item.RaiseClick(); - CloseMenu(item); + + if (!item.StaysOpenOnClick) + { + CloseMenu(item); + } } protected void CloseMenu(IMenuItem item) From 2635a8a7ef42707bcd55dafc980f8d7818b0ef0a Mon Sep 17 00:00:00 2001 From: Dariusz Komosinski Date: Thu, 29 Apr 2021 17:13:48 +0200 Subject: [PATCH 2/3] Fix copy pasta. --- src/Avalonia.Controls/MenuItem.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Avalonia.Controls/MenuItem.cs b/src/Avalonia.Controls/MenuItem.cs index 0995ce0e0b..4c801c2e06 100644 --- a/src/Avalonia.Controls/MenuItem.cs +++ b/src/Avalonia.Controls/MenuItem.cs @@ -70,7 +70,7 @@ namespace Avalonia.Controls AvaloniaProperty.Register(nameof(IsSubMenuOpen)); /// - /// Defines the property. + /// Defines the property. /// public static readonly StyledProperty StaysOpenOnClickProperty = AvaloniaProperty.Register(nameof(StaysOpenOnClick)); From d9510f77efeb3b28d1f4be682f707a7dbac0db44 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Fri, 30 Apr 2021 10:44:45 +0200 Subject: [PATCH 3/3] Update ApiCompatBaseline.txt --- src/Avalonia.Controls/ApiCompatBaseline.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Avalonia.Controls/ApiCompatBaseline.txt b/src/Avalonia.Controls/ApiCompatBaseline.txt index 3a6810eed9..7199c15d21 100644 --- a/src/Avalonia.Controls/ApiCompatBaseline.txt +++ b/src/Avalonia.Controls/ApiCompatBaseline.txt @@ -1,4 +1,7 @@ Compat issues with assembly Avalonia.Controls: +InterfacesShouldHaveSameMembers : Interface member 'public System.Boolean Avalonia.Controls.IMenuItem.StaysOpenOnClick' is present in the implementation but not in the contract. +InterfacesShouldHaveSameMembers : Interface member 'public System.Boolean Avalonia.Controls.IMenuItem.StaysOpenOnClick.get()' is present in the implementation but not in the contract. +InterfacesShouldHaveSameMembers : Interface member 'public void Avalonia.Controls.IMenuItem.StaysOpenOnClick.set(System.Boolean)' is present in the implementation but not in the contract. InterfacesShouldHaveSameMembers : Interface member 'public void Avalonia.Controls.INativeMenuExporterEventsImplBridge.RaiseClosed()' is present in the implementation but not in the contract. InterfacesShouldHaveSameMembers : Interface member 'public void Avalonia.Controls.INativeMenuExporterEventsImplBridge.RaiseOpening()' is present in the implementation but not in the contract. MembersMustExist : Member 'public void Avalonia.Controls.Embedding.Offscreen.OffscreenTopLevelImplBase.SetCursor(Avalonia.Platform.IPlatformHandle)' does not exist in the implementation but it does exist in the contract. @@ -7,4 +10,4 @@ EnumValuesMustMatch : Enum value 'Avalonia.Platform.ExtendClientAreaChromeHints InterfacesShouldHaveSameMembers : Interface member 'public void Avalonia.Platform.ITopLevelImpl.SetCursor(Avalonia.Platform.ICursorImpl)' is present in the implementation but not in the contract. InterfacesShouldHaveSameMembers : Interface member 'public void Avalonia.Platform.ITopLevelImpl.SetCursor(Avalonia.Platform.IPlatformHandle)' is present in the contract but not in the implementation. MembersMustExist : Member 'public void Avalonia.Platform.ITopLevelImpl.SetCursor(Avalonia.Platform.IPlatformHandle)' does not exist in the implementation but it does exist in the contract. -Total Issues: 7 +Total Issues: 11