Created
September 7, 2021 13:05
-
-
Save danwalmsley/5571ec43addf3639a052b84b0edeebc4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using Avalonia.Controls.Platform; | |
using Avalonia.Platform; | |
#nullable enable | |
namespace Avalonia.Controls | |
{ | |
public class TrayIcon : AvaloniaObject, IDataContextProvider | |
{ | |
private readonly ITrayIconImpl _impl; | |
private TrayIcon(ITrayIconImpl impl) | |
{ | |
_impl = impl; | |
} | |
public TrayIcon () : this(PlatformManager.CreateTrayIcon()) | |
{ | |
} | |
/// <summary> | |
/// Defines the <see cref="DataContext"/> property. | |
/// </summary> | |
public static readonly StyledProperty<object?> DataContextProperty = | |
StyledElement.DataContextProperty.AddOwner<Application>(); | |
/// <summary> | |
/// Defines the <see cref="Icon"/> property. | |
/// </summary> | |
public static readonly StyledProperty<WindowIcon> IconProperty = | |
Window.IconProperty.AddOwner<TrayIcon>(); | |
public static readonly StyledProperty<string?> ToolTipTextProperty = | |
AvaloniaProperty.Register<TrayIcon, string?>(nameof(ToolTipText)); | |
/// <summary> | |
/// Defines the <see cref="IsVisibleProperty"/> property. | |
/// </summary> | |
public static readonly StyledProperty<bool> IsVisibleProperty = | |
Visual.IsVisibleProperty.AddOwner<TrayIcon>(); | |
/// <summary> | |
/// Removes the notify icon from the taskbar notification area. | |
/// </summary> | |
public void Remove() | |
{ | |
} | |
/// <summary> | |
/// This event is raised when a user clicks on the notification icon. | |
/// </summary> | |
public event EventHandler<EventArgs> Clicked; | |
/// <summary> | |
/// This event is raised when a user doubleclicks on the notification icon. | |
/// </summary> | |
public event EventHandler<EventArgs> DoubleClicked; | |
/// <summary> | |
/// This event is raised when a user right-clicks on the notification icon. | |
/// </summary> | |
public event EventHandler<EventArgs> RightClicked; | |
public new ITrayIconImpl PlatformImpl => _impl; | |
/// <summary> | |
/// Gets or sets the Applications's data context. | |
/// </summary> | |
/// <remarks> | |
/// The data context property specifies the default object that will | |
/// be used for data binding. | |
/// </remarks> | |
public object? DataContext | |
{ | |
get => GetValue(DataContextProperty); | |
set => SetValue(DataContextProperty, value); | |
} | |
/// <summary> | |
/// Gets or sets the icon of the TrayIcon. | |
/// </summary> | |
public WindowIcon Icon | |
{ | |
get => GetValue(IconProperty); | |
set => SetValue(IconProperty, value); | |
} | |
/// <summary> | |
/// Gets or sets the tooltip text of the TrayIcon. | |
/// </summary> | |
public string? ToolTipText | |
{ | |
get => GetValue(ToolTipTextProperty); | |
set => SetValue(ToolTipTextProperty, value); | |
} | |
/// <summary> | |
/// Gets or sets the visibility of the TrayIcon. | |
/// </summary> | |
public bool IsVisible | |
{ | |
get => GetValue(IsVisibleProperty); | |
set => SetValue(IsVisibleProperty, value); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment