Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions README.adoc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
= Avalonia image:_docs/_Assets/Logo.svg[link=https://www.avaloniaui.net] Samples
= Avalonia image:_docs/_Assets/Logo.svg[link=https://www.avaloniaui.net] Samples
ifndef::env-github[]
:toc: left
endif::[]
Expand Down Expand Up @@ -108,6 +108,20 @@ Each sample is tagged with its difficulty. The degree of difficulty describes ho
|===


[#_desktop_integration_samples]
=== 🪟 DesktopIntegration-Samples

[cols="25h,25,50"]
|===
| Sample | Difficulty | Buzz-Words

| link:src/Avalonia.Samples/DesktopIntegration/TrayIcon[Tray Icon Sample]
| 🐣 Beginner
| TrayIcon, ReactiveUI, Binding

|===



[#_drawing_samples]
=== ✒️ Drawing-Samples
Expand Down Expand Up @@ -270,7 +284,7 @@ IMPORTANT: If you change the difficulty or the buzz-words, remember to also upda
.. link:/_docs/Markdown-Template/[Markdown-Template]: If you prefer not to use AsciiDoc, you can instead use the Markdown-template.

// Comment this in for next year's Hacktoberfest
////
////
=== 🎃 Hacktoberfest 2023

We are participating in https://hacktoberfest.com[[Hacktoberfest 2023\]]. If you submit a valid pull request within this month, we will add the `HACKTOBERFEST-ACCEPTED` label to your PR. Read more about it and how to participate https://hacktoberfest.com/participation/[[here\]].
Expand All @@ -281,7 +295,7 @@ Valid PRs are::
- Improving an existing sample
- Doing an overall spell-check (Not just changing a random word!)

WARNING: Spam or invalid PRs will be marked as invalid. If you are unsure if your PR will be accepted for Hacktoberfest, you can ask us here or in the image:https://raw.githubusercontent.com/Patrolavia/telegram-badge/master/chat.svg[link=https://t.me/Avalonia].
WARNING: Spam or invalid PRs will be marked as invalid. If you are unsure if your PR will be accepted for Hacktoberfest, you can ask us here or in the image:https://raw.githubusercontent.com/Patrolavia/telegram-badge/master/chat.svg[link=https://t.me/Avalonia].

🎃 Happy coding 🎃
////
9 changes: 9 additions & 0 deletions src/Avalonia.Samples/Avalonia.Samples.sln
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SnowflakesControlSample", "
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Avalonia.MusicStore", "CompleteApps\Avalonia.MusicStore\Avalonia.MusicStore.csproj", "{AA9BFD5E-9F4E-46CB-90FD-A4BAB9878A4A}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DesktopIntegration", "DesktopIntegration", "{8A863147-348B-47C4-902B-E132B62BB1C2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TrayIcon", "DesktopIntegration\TrayIcon\TrayIcon.csproj", "{EB8D1498-2528-4FE5-B2B0-515293A8880C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -314,6 +318,10 @@ Global
{AA9BFD5E-9F4E-46CB-90FD-A4BAB9878A4A}.Release|x64.Build.0 = Release|Any CPU
{AA9BFD5E-9F4E-46CB-90FD-A4BAB9878A4A}.Release|x86.ActiveCfg = Release|Any CPU
{AA9BFD5E-9F4E-46CB-90FD-A4BAB9878A4A}.Release|x86.Build.0 = Release|Any CPU
{EB8D1498-2528-4FE5-B2B0-515293A8880C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EB8D1498-2528-4FE5-B2B0-515293A8880C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EB8D1498-2528-4FE5-B2B0-515293A8880C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EB8D1498-2528-4FE5-B2B0-515293A8880C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -339,6 +347,7 @@ Global
{2B746401-384F-484A-810E-7A65288165E0} = {D02161B3-8242-4BF5-96E9-780465A5023B}
{B7B246E1-26F7-4225-A8FC-4344C1D7BA17} = {92C71AA7-E791-40C0-9F3A-2A85880B0439}
{AA9BFD5E-9F4E-46CB-90FD-A4BAB9878A4A} = {50FCF785-BBCF-4AFE-AC72-79EA9E92C43A}
{EB8D1498-2528-4FE5-B2B0-515293A8880C} = {8A863147-348B-47C4-902B-E132B62BB1C2}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C246CAB0-0837-4EE4-A22D-28B3C74930B4}
Expand Down
23 changes: 23 additions & 0 deletions src/Avalonia.Samples/DesktopIntegration/TrayIcon/AboutWindow.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<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="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>

<Label FontSize="24" HorizontalContentAlignment="Center" VerticalContentAlignment="Center">
Avalonia Tray Icon Sample
</Label>

<Label Name="lblActivationMode" Grid.Row="1" FontSize="16" HorizontalContentAlignment="Center" VerticalContentAlignment="Center">
Activated by...
</Label>

<Button Name="cmdClose" Click="cmdClose_Click" IsCancel="True" Grid.Row="2" Margin="30" HorizontalAlignment="Center">_Close</Button>
</Grid>
</Window>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Avalonia.Controls;
using Avalonia.Interactivity;

namespace TrayIcon
{
public partial class AboutWindow : Window
{
public AboutWindow()
{
InitializeComponent();
}

public void SetActivationMode(ActivationMode mode)
{
switch (mode)
{
case ActivationMode.Click: lblActivationMode.Content = "Activated by clicking"; break;
case ActivationMode.MenuItem: lblActivationMode.Content = "Activated by selecting menu item"; break;
}
}

void cmdClose_Click(object? sender, RoutedEventArgs e)
{
this.Close();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace TrayIcon
{
public enum ActivationMode
{
Click,
MenuItem,
}
}
25 changes: 25 additions & 0 deletions src/Avalonia.Samples/DesktopIntegration/TrayIcon/App.axaml
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" Command="{Binding TrayIconClickedCommand}">
<TrayIcon.Menu>
<NativeMenu>
<NativeMenuItem Header="_About" Command="{Binding ShowAboutWindowCommand}" />
<NativeMenuItemSeparator />
<NativeMenuItem Header="E_xit" Command="{Binding ExitApplicationCommand}" />
</NativeMenu>
</TrayIcon.Menu>
</TrayIcon>
</TrayIcons>
</TrayIcon.Icons>
</Application>
68 changes: 68 additions & 0 deletions src/Avalonia.Samples/DesktopIntegration/TrayIcon/App.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using System.Windows.Input;

using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;

using CommunityToolkit.Mvvm.Input;

namespace TrayIcon
{
public partial class App : Application
{
public override void Initialize()
{
AvaloniaXamlLoader.Load(this);
}

public App()
{
DataContext = this;
}

public override void OnFrameworkInitializationCompleted()
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
desktop.ShutdownMode = Avalonia.Controls.ShutdownMode.OnExplicitShutdown;
}

base.OnFrameworkInitializationCompleted();
}

[RelayCommand]
public void TrayIconClicked()
{
var window = new AboutWindow();

window.SetActivationMode(ActivationMode.Click);

window.Show();
}

[RelayCommand]
public void ShowAboutWindow()
{
var window = new AboutWindow();

window.SetActivationMode(ActivationMode.MenuItem);

window.Show();
}

[RelayCommand]
public void ExitApplication()
{
switch (ApplicationLifetime)
{
case IClassicDesktopStyleApplicationLifetime desktopLifetime:
desktopLifetime.TryShutdown();
break;
case IControlledApplicationLifetime controlledLifetime:
controlledLifetime.Shutdown();
break;
}
}
}
}

18 changes: 18 additions & 0 deletions src/Avalonia.Samples/DesktopIntegration/TrayIcon/App.manifest
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>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
using System.Runtime.CompilerServices;
Binary file not shown.
27 changes: 27 additions & 0 deletions src/Avalonia.Samples/DesktopIntegration/TrayIcon/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;

using Avalonia;

namespace TrayIcon
{
class Program
{
[STAThread]
public static void Main(string[] args)
{
Console.WriteLine("Check the system notification area for a new icon");

var app = BuildAvaloniaApp();

app.StartWithClassicDesktopLifetime(args);
}

public static AppBuilder BuildAvaloniaApp()
{
return AppBuilder.Configure<App>()
.UsePlatformDetect()
.WithInterFont()
.LogToTrace();
}
}
}
9 changes: 9 additions & 0 deletions src/Avalonia.Samples/DesktopIntegration/TrayIcon/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# TrayIcon

Sample application that shows a tray icon.

![Screenshot of TrayIcon Sample](Screenshot.png "TrayIcon in action")

* The tray icon must have an associated icon. The icon should be included in the project as an `<AvaloniaResource>`.
* This sample sets the `DataContext` for `App` to `this`, which allows the command to be defined in the same class and then bound in the `.axaml` file. Consider using a separate view model in production code.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions src/Avalonia.Samples/DesktopIntegration/TrayIcon/TrayIcon.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<IncludeAvaloniaGenerators>true</IncludeAvaloniaGenerators>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.3.8" />
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.3.8" />
<PackageReference Include="Avalonia.Desktop" Version="11.3.8" />
<PackageReference Include="Avalonia.Diagnostics" Version="11.3.8" />
<PackageReference Include="Avalonia.Remote.Protocol" Version="11.3.8" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" />
</ItemGroup>

<ItemGroup>
<AvaloniaResource Include="Icon.ico" />
</ItemGroup>
</Project>