-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added sample TrayIcon which crashes when a tray icon menu item is act…
…ivated.
- Loading branch information
Showing
9 changed files
with
187 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<Window xmlns="https://github.com/avaloniaui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
x:Class="TrayIcon.AboutWindow" | ||
Title="Avalonia Tray Icon Sample" | ||
Width="800" Height="400" WindowState="Normal" WindowStartupLocation="CenterScreen"> | ||
<Grid> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="*" /> | ||
<RowDefinition Height="Auto" /> | ||
</Grid.RowDefinitions> | ||
|
||
<Label FontSize="24" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"> | ||
Avalonia Tray Icon Sample | ||
</Label> | ||
|
||
<Button Name="cmdClose" Click="cmdClose_Click" Grid.Row="1" Margin="30" HorizontalAlignment="Center">_Close</Button> | ||
</Grid> | ||
</Window> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<Application xmlns="https://github.com/avaloniaui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="using:TrayIcon" | ||
x:Class="TrayIcon.App" | ||
x:CompileBindings="true" | ||
x:DataType="local:App" | ||
RequestedThemeVariant="Default"> | ||
<Application.Styles> | ||
<FluentTheme /> | ||
</Application.Styles> | ||
|
||
<TrayIcon.Icons> | ||
<TrayIcons> | ||
<TrayIcon Icon="Icon.ico" ToolTipText="TrayIcon Sample"> | ||
<TrayIcon.Menu> | ||
<NativeMenu> | ||
<NativeMenuItem Header="_About" Command="{Binding AboutCommand}" /> | ||
<NativeMenuItemSeparator /> | ||
<NativeMenuItem Header="E_xit" Command="{Binding ExitCommand}" /> | ||
</NativeMenu> | ||
</TrayIcon.Menu> | ||
</TrayIcon> | ||
</TrayIcons> | ||
</TrayIcon.Icons> | ||
</Application> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} | ||
} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1"> | ||
<!-- This manifest is used on Windows only. | ||
Don't remove it as it might cause problems with window transparency and embedded controls. | ||
For more details visit https://learn.microsoft.com/en-us/windows/win32/sbscs/application-manifests --> | ||
<assemblyIdentity version="1.0.0.0" name="DeltaQ.RTB.UserInterface.Desktop"/> | ||
|
||
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1"> | ||
<application> | ||
<!-- A list of the Windows versions that this application has been tested on | ||
and is designed to work with. Uncomment the appropriate elements | ||
and Windows will automatically select the most compatible environment. --> | ||
|
||
<!-- Windows 10 --> | ||
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" /> | ||
</application> | ||
</compatibility> | ||
</assembly> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
using System.Runtime.CompilerServices; |
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<App>() | ||
.UsePlatformDetect() | ||
.WithInterFont() | ||
.LogToTrace(); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>WinExe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<IncludeAvaloniaGenerators>true</IncludeAvaloniaGenerators> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\Avalonia.Themes.Fluent\Avalonia.Themes.Fluent.csproj" /> | ||
<ProjectReference Include="..\..\src\Avalonia.Fonts.Inter\Avalonia.Fonts.Inter.csproj" /> | ||
<ProjectReference Include="..\..\src\Avalonia.ReactiveUI\Avalonia.ReactiveUI.csproj" /> | ||
<ProjectReference Include="..\..\src\Avalonia.Desktop\Avalonia.Desktop.csproj" /> | ||
<ProjectReference Include="..\..\src\Avalonia.Diagnostics\Avalonia.Diagnostics.csproj" /> | ||
<ProjectReference Include="..\..\src\Avalonia.Remote.Protocol\Avalonia.Remote.Protocol.csproj" /> | ||
</ItemGroup> | ||
|
||
<Import Project="..\..\build\SampleApp.props" /> | ||
<Import Project="..\..\build\ReferenceCoreLibraries.props" /> | ||
<Import Project="..\..\build\BuildTargets.targets" /> | ||
<Import Project="..\..\build\SourceGenerators.props" /> | ||
|
||
<ItemGroup> | ||
<AvaloniaResource Include="Icon.ico" /> | ||
</ItemGroup> | ||
</Project> |