diff --git a/samples/TrayIcon/AboutWindow.axaml b/samples/TrayIcon/AboutWindow.axaml new file mode 100644 index 00000000000..acd68966e85 --- /dev/null +++ b/samples/TrayIcon/AboutWindow.axaml @@ -0,0 +1,18 @@ + + + + + + + + + + + + diff --git a/samples/TrayIcon/AboutWindow.axaml.cs b/samples/TrayIcon/AboutWindow.axaml.cs new file mode 100644 index 00000000000..766e3b3fa93 --- /dev/null +++ b/samples/TrayIcon/AboutWindow.axaml.cs @@ -0,0 +1,18 @@ +using Avalonia.Controls; +using Avalonia.Interactivity; + +namespace TrayIcon +{ + public partial class AboutWindow : Window + { + public AboutWindow() + { + InitializeComponent(); + } + + void cmdClose_Click(object? sender, RoutedEventArgs e) + { + this.Close(); + } + } +} diff --git a/samples/TrayIcon/App.axaml b/samples/TrayIcon/App.axaml new file mode 100644 index 00000000000..148ed0211d7 --- /dev/null +++ b/samples/TrayIcon/App.axaml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + diff --git a/samples/TrayIcon/App.axaml.cs b/samples/TrayIcon/App.axaml.cs new file mode 100644 index 00000000000..12887819c79 --- /dev/null +++ b/samples/TrayIcon/App.axaml.cs @@ -0,0 +1,56 @@ +using System.Windows.Input; + +using Avalonia; +using Avalonia.Controls.ApplicationLifetimes; +using Avalonia.Markup.Xaml; + +using ReactiveUI; + +namespace TrayIcon +{ + public partial class App : Application + { + public override void Initialize() + { + AvaloniaXamlLoader.Load(this); + } + + public App() + { + AboutCommand = ReactiveCommand.Create(ShowAboutWindow); + ExitCommand = ReactiveCommand.Create(ExitApplication); + + DataContext = this; + } + + public override void OnFrameworkInitializationCompleted() + { + if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) + { + _lifetime = desktop; + + desktop.ShutdownMode = Avalonia.Controls.ShutdownMode.OnExplicitShutdown; + } + + base.OnFrameworkInitializationCompleted(); + } + + IClassicDesktopStyleApplicationLifetime? _lifetime; + + public ICommand AboutCommand { get; } + public ICommand ExitCommand { get; } + + void ShowAboutWindow() + { + var window = new AboutWindow(); + + window.Show(); + } + + void ExitApplication() + { + _lifetime?.Shutdown(); + } + } +} + diff --git a/samples/TrayIcon/App.manifest b/samples/TrayIcon/App.manifest new file mode 100644 index 00000000000..bedffa84da6 --- /dev/null +++ b/samples/TrayIcon/App.manifest @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + diff --git a/samples/TrayIcon/AssemblyInfo.cs b/samples/TrayIcon/AssemblyInfo.cs new file mode 100644 index 00000000000..d09de88802a --- /dev/null +++ b/samples/TrayIcon/AssemblyInfo.cs @@ -0,0 +1 @@ +using System.Runtime.CompilerServices; diff --git a/samples/TrayIcon/Icon.ico b/samples/TrayIcon/Icon.ico new file mode 100644 index 00000000000..1c290f21a6c Binary files /dev/null and b/samples/TrayIcon/Icon.ico differ diff --git a/samples/TrayIcon/Program.cs b/samples/TrayIcon/Program.cs new file mode 100644 index 00000000000..91ec561faba --- /dev/null +++ b/samples/TrayIcon/Program.cs @@ -0,0 +1,25 @@ +using System; + +using Avalonia; + +namespace TrayIcon +{ + class Program + { + [STAThread] + public static void Main(string[] args) + { + var app = BuildAvaloniaApp(); + + app.StartWithClassicDesktopLifetime(args); + } + + public static AppBuilder BuildAvaloniaApp() + { + return AppBuilder.Configure() + .UsePlatformDetect() + .WithInterFont() + .LogToTrace(); + } + } +} diff --git a/samples/TrayIcon/TrayIcon.csproj b/samples/TrayIcon/TrayIcon.csproj new file mode 100644 index 00000000000..5792ca84242 --- /dev/null +++ b/samples/TrayIcon/TrayIcon.csproj @@ -0,0 +1,26 @@ + + + WinExe + net8.0 + enable + true + + + + + + + + + + + + + + + + + + + +