A cross-platform UI framework for .NET
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

66 lines
1.6 KiB

using System;
using System.IO;
using Avalonia.Controls.Platform;
using Avalonia.Native.Interop;
using Avalonia.Platform;
namespace Avalonia.Native
{
internal class TrayIconImpl : ITrayIconWithIsTemplateImpl
{
private readonly IAvnTrayIcon _native;
public TrayIconImpl(IAvaloniaNativeFactory factory)
{
_native = factory.CreateTrayIcon();
MenuExporter = new AvaloniaNativeMenuExporter(_native, factory);
}
public Action? OnClicked { get; set; }
public void Dispose()
{
_native.Dispose();
}
public unsafe void SetIcon(IWindowIconImpl? icon)
{
if (icon is null)
{
_native.SetIcon(null, IntPtr.Zero);
}
else
{
using (var ms = new MemoryStream())
{
icon.Save(ms);
var imageData = ms.ToArray();
fixed (void* ptr = imageData)
{
_native.SetIcon(ptr, new IntPtr(imageData.Length));
}
}
}
}
public void SetToolTipText(string? text)
{
_native.SetToolTipText(text);
}
public void SetIsVisible(bool visible)
{
_native.SetIsVisible(visible.AsComBool());
}
public void SetIsTemplateIcon(bool isTemplateIcon)
{
_native.SetIsTemplateIcon(isTemplateIcon.AsComBool());
}
public INativeMenuExporter? MenuExporter { get; }
}
}