Browse Source

make the trayicon menu property an explicit member of trayicon.

pull/6560/head
Dan Walmsley 4 years ago
parent
commit
34b96f45f3
  1. 4
      samples/ControlCatalog/App.xaml
  2. 2
      src/Avalonia.Controls/Platform/ITopLevelNativeMenuExporter.cs
  3. 19
      src/Avalonia.Controls/TrayIcon.cs

4
samples/ControlCatalog/App.xaml

@ -30,7 +30,7 @@
<TrayIcon.Icons>
<TrayIcons>
<TrayIcon Icon="/Assets/test_icon.ico" ToolTipText="Avalonia Tray Icon ToolTip">
<NativeMenu.Menu>
<TrayIcon.Menu>
<NativeMenu>
<NativeMenuItem Header="Settings">
<NativeMenu>
@ -43,7 +43,7 @@
</NativeMenuItem>
<NativeMenuItem Header="Exit" Command="{Binding ExitCommand}" />
</NativeMenu>
</NativeMenu.Menu>
</TrayIcon.Menu>
</TrayIcon>
</TrayIcons>
</TrayIcon.Icons>

2
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

19
src/Avalonia.Controls/TrayIcon.cs

@ -68,6 +68,12 @@ namespace Avalonia.Controls
public static readonly AttachedProperty<TrayIcons> IconsProperty
= AvaloniaProperty.RegisterAttached<TrayIcon, Application, TrayIcons>("Icons");
/// <summary>
/// Defines the <see cref="Menu"/> property.
/// </summary>
public static readonly StyledProperty<NativeMenu?> MenuProperty
= AvaloniaProperty.Register<TrayIcon, NativeMenu?>(nameof(Menu));
/// <summary>
/// Defines the <see cref="Icon"/> property.
/// </summary>
@ -90,6 +96,15 @@ namespace Avalonia.Controls
public static TrayIcons GetIcons(AvaloniaObject o) => o.GetValue(IconsProperty);
/// <summary>
/// Gets or sets the Menu of the TrayIcon.
/// </summary>
public NativeMenu? Menu
{
get => GetValue(MenuProperty);
set => SetValue(MenuProperty, value);
}
/// <summary>
/// Gets or sets the icon of the TrayIcon.
/// </summary>
@ -155,6 +170,10 @@ namespace Avalonia.Controls
{
_impl.SetToolTipText(change.NewValue.GetValueOrDefault<string?>());
}
else if (change.Property == MenuProperty)
{
_impl.MenuExporter?.SetNativeMenu(change.NewValue.GetValueOrDefault<NativeMenu>());
}
}
/// <summary>

Loading…
Cancel
Save