Skip to content

Commit 2420c6f

Browse files
timunielogiclrd
andauthored
TrayIcon-Samples (#211)
* Added TrayIcon sample app. * Updates - Upgrade dependencies - Use CommuntiyToolkitMVVM for Commands - Resolve conflicts --------- Co-authored-by: Jonathan Gilbert <logic@deltaq.org>
1 parent 6494689 commit 2420c6f

File tree

12 files changed

+216
-1
lines changed

12 files changed

+216
-1
lines changed

README.adoc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,18 @@ Each sample is tagged with its difficulty. The degree of difficulty describes ho
107107
108108
|===
109109
110+
=== DesktopIntegration-Samples
111+
112+
[cols="25h,25,50"]
113+
|===
114+
| Sample | Difficulty | Buzz-Words
115+
116+
| link:src/Avalonia.Samples/Desktop/TrayIcon[Tray Icon Sample]
117+
| 🐣 Beginner
118+
| TrayIcon, ReactiveUI, Binding
119+
120+
|===
121+
110122
111123
112124
[#_drawing_samples]

src/Avalonia.Samples/Avalonia.Samples.sln

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 17
44
VisualStudioVersion = 17.2.32616.157
@@ -64,6 +64,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SnowflakesControlSample", "
6464
EndProject
6565
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Avalonia.MusicStore", "CompleteApps\Avalonia.MusicStore\Avalonia.MusicStore.csproj", "{AA9BFD5E-9F4E-46CB-90FD-A4BAB9878A4A}"
6666
EndProject
67+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DesktopIntegration", "DesktopIntegration", "{2FBF7E83-2410-43D0-AC59-9292D779674C}"
68+
EndProject
69+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TrayIcon", "DesktopIntegration\TrayIcon\TrayIcon.csproj", "{D539FEE4-6228-4842-A61D-ABB281254F1A}"
70+
EndProject
6771
Global
6872
GlobalSection(SolutionConfigurationPlatforms) = preSolution
6973
Debug|Any CPU = Debug|Any CPU
@@ -314,6 +318,18 @@ Global
314318
{AA9BFD5E-9F4E-46CB-90FD-A4BAB9878A4A}.Release|x64.Build.0 = Release|Any CPU
315319
{AA9BFD5E-9F4E-46CB-90FD-A4BAB9878A4A}.Release|x86.ActiveCfg = Release|Any CPU
316320
{AA9BFD5E-9F4E-46CB-90FD-A4BAB9878A4A}.Release|x86.Build.0 = Release|Any CPU
321+
{D539FEE4-6228-4842-A61D-ABB281254F1A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
322+
{D539FEE4-6228-4842-A61D-ABB281254F1A}.Debug|Any CPU.Build.0 = Debug|Any CPU
323+
{D539FEE4-6228-4842-A61D-ABB281254F1A}.Debug|x64.ActiveCfg = Debug|Any CPU
324+
{D539FEE4-6228-4842-A61D-ABB281254F1A}.Debug|x64.Build.0 = Debug|Any CPU
325+
{D539FEE4-6228-4842-A61D-ABB281254F1A}.Debug|x86.ActiveCfg = Debug|Any CPU
326+
{D539FEE4-6228-4842-A61D-ABB281254F1A}.Debug|x86.Build.0 = Debug|Any CPU
327+
{D539FEE4-6228-4842-A61D-ABB281254F1A}.Release|Any CPU.ActiveCfg = Release|Any CPU
328+
{D539FEE4-6228-4842-A61D-ABB281254F1A}.Release|Any CPU.Build.0 = Release|Any CPU
329+
{D539FEE4-6228-4842-A61D-ABB281254F1A}.Release|x64.ActiveCfg = Release|Any CPU
330+
{D539FEE4-6228-4842-A61D-ABB281254F1A}.Release|x64.Build.0 = Release|Any CPU
331+
{D539FEE4-6228-4842-A61D-ABB281254F1A}.Release|x86.ActiveCfg = Release|Any CPU
332+
{D539FEE4-6228-4842-A61D-ABB281254F1A}.Release|x86.Build.0 = Release|Any CPU
317333
EndGlobalSection
318334
GlobalSection(SolutionProperties) = preSolution
319335
HideSolutionNode = FALSE
@@ -339,6 +355,7 @@ Global
339355
{2B746401-384F-484A-810E-7A65288165E0} = {D02161B3-8242-4BF5-96E9-780465A5023B}
340356
{B7B246E1-26F7-4225-A8FC-4344C1D7BA17} = {92C71AA7-E791-40C0-9F3A-2A85880B0439}
341357
{AA9BFD5E-9F4E-46CB-90FD-A4BAB9878A4A} = {50FCF785-BBCF-4AFE-AC72-79EA9E92C43A}
358+
{D539FEE4-6228-4842-A61D-ABB281254F1A} = {2FBF7E83-2410-43D0-AC59-9292D779674C}
342359
EndGlobalSection
343360
GlobalSection(ExtensibilityGlobals) = postSolution
344361
SolutionGuid = {C246CAB0-0837-4EE4-A22D-28B3C74930B4}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<Window xmlns="https://github.com/avaloniaui"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3+
x:Class="TrayIcon.AboutWindow"
4+
Title="Avalonia Tray Icon Sample"
5+
Width="800" Height="400" WindowState="Normal" WindowStartupLocation="CenterScreen">
6+
<Grid>
7+
<Grid.RowDefinitions>
8+
<RowDefinition Height="*" />
9+
<RowDefinition Height="Auto" />
10+
</Grid.RowDefinitions>
11+
12+
<Label FontSize="24" HorizontalContentAlignment="Center" VerticalContentAlignment="Center">
13+
Avalonia Tray Icon Sample
14+
</Label>
15+
16+
<Button Name="cmdClose" Click="cmdClose_Click" Grid.Row="1" Margin="30" HorizontalAlignment="Center">_Close</Button>
17+
</Grid>
18+
</Window>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using Avalonia.Controls;
2+
using Avalonia.Interactivity;
3+
4+
namespace TrayIcon
5+
{
6+
public partial class AboutWindow : Window
7+
{
8+
public AboutWindow()
9+
{
10+
InitializeComponent();
11+
}
12+
13+
void cmdClose_Click(object? sender, RoutedEventArgs e)
14+
{
15+
this.Close();
16+
}
17+
}
18+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<Application xmlns="https://github.com/avaloniaui"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3+
xmlns:local="using:TrayIcon"
4+
x:Class="TrayIcon.App"
5+
x:CompileBindings="true"
6+
x:DataType="local:App"
7+
RequestedThemeVariant="Default">
8+
<Application.Styles>
9+
<FluentTheme />
10+
</Application.Styles>
11+
12+
<TrayIcon.Icons>
13+
<TrayIcons>
14+
<TrayIcon Icon="Icon.ico" ToolTipText="TrayIcon Sample">
15+
<TrayIcon.Menu>
16+
<NativeMenu>
17+
<NativeMenuItem Header="_About" Command="{Binding ShowAboutCommand}" />
18+
<NativeMenuItemSeparator />
19+
<NativeMenuItem Header="E_xit" Command="{Binding ExitApplicationCommand}" />
20+
</NativeMenu>
21+
</TrayIcon.Menu>
22+
</TrayIcon>
23+
</TrayIcons>
24+
</TrayIcon.Icons>
25+
</Application>
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using Avalonia;
2+
using Avalonia.Controls.ApplicationLifetimes;
3+
using Avalonia.Markup.Xaml;
4+
using CommunityToolkit.Mvvm.Input;
5+
6+
namespace TrayIcon
7+
{
8+
public partial class App : Application
9+
{
10+
public override void Initialize()
11+
{
12+
AvaloniaXamlLoader.Load(this);
13+
}
14+
15+
public App()
16+
{
17+
DataContext = this;
18+
}
19+
20+
public override void OnFrameworkInitializationCompleted()
21+
{
22+
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
23+
{
24+
desktop.ShutdownMode = Avalonia.Controls.ShutdownMode.OnExplicitShutdown;
25+
}
26+
27+
base.OnFrameworkInitializationCompleted();
28+
}
29+
30+
[RelayCommand]
31+
public void ShowAbout()
32+
{
33+
var window = new AboutWindow();
34+
35+
window.Show();
36+
}
37+
38+
[RelayCommand]
39+
void ExitApplication()
40+
{
41+
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktopLifetime)
42+
{
43+
desktopLifetime.TryShutdown();
44+
}
45+
else if (ApplicationLifetime is IControlledApplicationLifetime controlledLifetime)
46+
{
47+
controlledLifetime.Shutdown();
48+
}
49+
}
50+
}
51+
}
52+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
3+
<!-- This manifest is used on Windows only.
4+
Don't remove it as it might cause problems with window transparency and embedded controls.
5+
For more details visit https://learn.microsoft.com/en-us/windows/win32/sbscs/application-manifests -->
6+
<assemblyIdentity version="1.0.0.0" name="DeltaQ.RTB.UserInterface.Desktop"/>
7+
8+
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
9+
<application>
10+
<!-- A list of the Windows versions that this application has been tested on
11+
and is designed to work with. Uncomment the appropriate elements
12+
and Windows will automatically select the most compatible environment. -->
13+
14+
<!-- Windows 10 -->
15+
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
16+
</application>
17+
</compatibility>
18+
</assembly>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
using System.Runtime.CompilerServices;
82.2 KB
Binary file not shown.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
3+
using Avalonia;
4+
5+
namespace TrayIcon
6+
{
7+
class Program
8+
{
9+
[STAThread]
10+
public static void Main(string[] args)
11+
{
12+
var app = BuildAvaloniaApp();
13+
14+
app.StartWithClassicDesktopLifetime(args);
15+
}
16+
17+
public static AppBuilder BuildAvaloniaApp()
18+
{
19+
return AppBuilder.Configure<App>()
20+
.UsePlatformDetect()
21+
.WithInterFont()
22+
.LogToTrace();
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)