From 34b96f45f30bc35c43eebee3796feba4513501cc Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Mon, 4 Oct 2021 17:55:30 +0100 Subject: [PATCH] make the trayicon menu property an explicit member of trayicon. --- samples/ControlCatalog/App.xaml | 4 ++-- .../Platform/ITopLevelNativeMenuExporter.cs | 2 +- src/Avalonia.Controls/TrayIcon.cs | 19 +++++++++++++++++++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/samples/ControlCatalog/App.xaml b/samples/ControlCatalog/App.xaml index 845413a455..6e57686e00 100644 --- a/samples/ControlCatalog/App.xaml +++ b/samples/ControlCatalog/App.xaml @@ -30,7 +30,7 @@ - + @@ -43,7 +43,7 @@ - + diff --git a/src/Avalonia.Controls/Platform/ITopLevelNativeMenuExporter.cs b/src/Avalonia.Controls/Platform/ITopLevelNativeMenuExporter.cs index 5e5f7b18ec..9b779054f3 100644 --- a/src/Avalonia.Controls/Platform/ITopLevelNativeMenuExporter.cs +++ b/src/Avalonia.Controls/Platform/ITopLevelNativeMenuExporter.cs @@ -7,7 +7,7 @@ namespace Avalonia.Controls.Platform { public interface INativeMenuExporter { - void SetNativeMenu(NativeMenu menu); + void SetNativeMenu(NativeMenu? menu); } public interface ITopLevelNativeMenuExporter : INativeMenuExporter diff --git a/src/Avalonia.Controls/TrayIcon.cs b/src/Avalonia.Controls/TrayIcon.cs index 7b400d3600..5b10fa20ea 100644 --- a/src/Avalonia.Controls/TrayIcon.cs +++ b/src/Avalonia.Controls/TrayIcon.cs @@ -68,6 +68,12 @@ namespace Avalonia.Controls public static readonly AttachedProperty IconsProperty = AvaloniaProperty.RegisterAttached("Icons"); + /// + /// Defines the property. + /// + public static readonly StyledProperty MenuProperty + = AvaloniaProperty.Register(nameof(Menu)); + /// /// Defines the property. /// @@ -90,6 +96,15 @@ namespace Avalonia.Controls public static TrayIcons GetIcons(AvaloniaObject o) => o.GetValue(IconsProperty); + /// + /// Gets or sets the Menu of the TrayIcon. + /// + public NativeMenu? Menu + { + get => GetValue(MenuProperty); + set => SetValue(MenuProperty, value); + } + /// /// Gets or sets the icon of the TrayIcon. /// @@ -155,6 +170,10 @@ namespace Avalonia.Controls { _impl.SetToolTipText(change.NewValue.GetValueOrDefault()); } + else if (change.Property == MenuProperty) + { + _impl.MenuExporter?.SetNativeMenu(change.NewValue.GetValueOrDefault()); + } } ///