Skip to content

Commit

Permalink
Add Avalonia sample application with acrylic blur effect wthout decor…
Browse files Browse the repository at this point in the history
…ations
  • Loading branch information
acidicMercury8 committed May 13, 2024
1 parent 1ed2cdb commit 14c6151
Show file tree
Hide file tree
Showing 12 changed files with 198 additions and 1 deletion.
8 changes: 7 additions & 1 deletion avalonia-samples-csharp/AvaloniaSamples.sln
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DockingApplication", "src\D
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AnimationsApplication", "src\AnimationsApplication\AnimationsApplication.csproj", "{2BEDA4BF-485D-42A5-9721-A01D2C8C7772}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LocalizationApplication", "src\LocalizationApplication\LocalizationApplication.csproj", "{400502EC-9DC5-42C4-AE36-9DB196CA6BF5}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LocalizationApplication", "src\LocalizationApplication\LocalizationApplication.csproj", "{400502EC-9DC5-42C4-AE36-9DB196CA6BF5}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AcrylicBlurWthoutDecoration", "src\AcrylicBlurWthoutDecoration\AcrylicBlurWthoutDecoration.csproj", "{FAB1B5B5-254F-478A-8DC6-AD3E9BBA1C1B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -39,6 +41,10 @@ Global
{400502EC-9DC5-42C4-AE36-9DB196CA6BF5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{400502EC-9DC5-42C4-AE36-9DB196CA6BF5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{400502EC-9DC5-42C4-AE36-9DB196CA6BF5}.Release|Any CPU.Build.0 = Release|Any CPU
{FAB1B5B5-254F-478A-8DC6-AD3E9BBA1C1B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FAB1B5B5-254F-478A-8DC6-AD3E9BBA1C1B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FAB1B5B5-254F-478A-8DC6-AD3E9BBA1C1B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FAB1B5B5-254F-478A-8DC6-AD3E9BBA1C1B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>

<ItemGroup>
<AvaloniaResource Include="Assets\**" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Avalonia" Version="11.0.10" />
<PackageReference Include="Avalonia.Desktop" Version="11.0.10" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.0.10" />
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.0.10" />
<PackageReference Include="Avalonia.Diagnostics" Version="11.0.10" Condition="'$(Configuration)' == 'Debug'" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
</ItemGroup>
</Project>
14 changes: 14 additions & 0 deletions avalonia-samples-csharp/src/AcrylicBlurWthoutDecoration/App.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Application xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="AcrylicBlurWthoutDecoration.App"
xmlns:local="using:AcrylicBlurWthoutDecoration"
RequestedThemeVariant="Default">
<!-- "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options. -->
<Application.DataTemplates>
<local:ViewLocator/>
</Application.DataTemplates>

<Application.Styles>
<FluentTheme />
</Application.Styles>
</Application>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using AcrylicBlurWthoutDecoration.ViewModels;
using AcrylicBlurWthoutDecoration.Views;

using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Data.Core;
using Avalonia.Data.Core.Plugins;
using Avalonia.Markup.Xaml;

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

public override void OnFrameworkInitializationCompleted() {
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) {
// Line below is needed to remove Avalonia data validation.
// Without this line you will get duplicate validations from both Avalonia and CT
BindingPlugins.DataValidators.RemoveAt(0);
desktop.MainWindow = new MainWindow {
DataContext = new MainWindowViewModel(),
};
}

base.OnFrameworkInitializationCompleted();
}
}
}
Binary file not shown.
21 changes: 21 additions & 0 deletions avalonia-samples-csharp/src/AcrylicBlurWthoutDecoration/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;

using Avalonia;

namespace AcrylicBlurWthoutDecoration {
internal class Program {
// Initialization code. Don't use any Avalonia, third-party APIs or any
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
// yet and stuff might break.
[STAThread]
public static void Main(string[] args) => BuildAvaloniaApp()
.StartWithClassicDesktopLifetime(args);

// Avalonia configuration, don't remove; also used by visual designer.
public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>()
.UsePlatformDetect()
.WithInterFont()
.LogToTrace();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;

using AcrylicBlurWthoutDecoration.ViewModels;

using Avalonia.Controls;
using Avalonia.Controls.Templates;

namespace AcrylicBlurWthoutDecoration {
public class ViewLocator : IDataTemplate {
public Control Build(object data) {
var name = data.GetType().FullName!.Replace("ViewModel", "View");
var type = Type.GetType(name);

if (type != null) {
return (Control) Activator.CreateInstance(type)!;
}

return new TextBlock { Text = "Not Found: " + name };
}

public bool Match(object data) {
return data is ViewModelBase;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace AcrylicBlurWthoutDecoration.ViewModels;

public partial class MainWindowViewModel : ViewModelBase {
public string Greeting => "Welcome to Avalonia!";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
using CommunityToolkit.Mvvm.ComponentModel;

namespace AcrylicBlurWthoutDecoration.ViewModels;

public class ViewModelBase : ObservableObject {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<Window
x:Class="AcrylicBlurWthoutDecoration.Views.MainWindow"
x:DataType="vm:MainWindowViewModel"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:vm="using:AcrylicBlurWthoutDecoration.ViewModels"
Title="AcrylicBlurWthoutDecoration"
Width="300"
Height="400"
d:DesignHeight="300"
d:DesignWidth="400"
Background="Transparent"
CanResize="False"
ExtendClientAreaToDecorationsHint="True"
Icon="/Assets/avalonia-logo.ico"
SystemDecorations="None"
TransparencyLevelHint="AcrylicBlur"
WindowStartupLocation="CenterScreen"
mc:Ignorable="d">
<Design.DataContext>
<vm:MainWindowViewModel />
</Design.DataContext>

<Border>
<ExperimentalAcrylicBorder
CornerRadius="10"
IsHitTestVisible="False">
<ExperimentalAcrylicBorder.Material>
<ExperimentalAcrylicMaterial
BackgroundSource="Digger"
MaterialOpacity="0.1"
TintColor="Black"
TintOpacity="1" />
</ExperimentalAcrylicBorder.Material>

<TextBlock
Text="{Binding Greeting}"
HorizontalAlignment="Center"
VerticalAlignment="Center" />
</ExperimentalAcrylicBorder>
</Border>
</Window>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using Avalonia.Controls;

namespace AcrylicBlurWthoutDecoration.Views;

public partial class MainWindow : Window {
public MainWindow() => InitializeComponent();
}
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 embeded controls.
For more details visit https://learn.microsoft.com/en-us/windows/win32/sbscs/application-manifests -->
<assemblyIdentity version="1.0.0.0" name="AcrylicBlurWthoutDecoration"/>

<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>

0 comments on commit 14c6151

Please sign in to comment.