-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Avalonia sample application with acrylic blur effect wthout decor…
…ations
- Loading branch information
1 parent
1ed2cdb
commit 14c6151
Showing
12 changed files
with
198 additions
and
1 deletion.
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
22 changes: 22 additions & 0 deletions
22
avalonia-samples-csharp/src/AcrylicBlurWthoutDecoration/AcrylicBlurWthoutDecoration.csproj
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,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
14
avalonia-samples-csharp/src/AcrylicBlurWthoutDecoration/App.axaml
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,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> |
29 changes: 29 additions & 0 deletions
29
avalonia-samples-csharp/src/AcrylicBlurWthoutDecoration/App.axaml.cs
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,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 added
BIN
+172 KB
avalonia-samples-csharp/src/AcrylicBlurWthoutDecoration/Assets/avalonia-logo.ico
Binary file not shown.
21 changes: 21 additions & 0 deletions
21
avalonia-samples-csharp/src/AcrylicBlurWthoutDecoration/Program.cs
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,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(); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
avalonia-samples-csharp/src/AcrylicBlurWthoutDecoration/ViewLocator.cs
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 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; | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
avalonia-samples-csharp/src/AcrylicBlurWthoutDecoration/ViewModels/MainWindowViewModel.cs
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,5 @@ | ||
namespace AcrylicBlurWthoutDecoration.ViewModels; | ||
|
||
public partial class MainWindowViewModel : ViewModelBase { | ||
public string Greeting => "Welcome to Avalonia!"; | ||
} |
6 changes: 6 additions & 0 deletions
6
avalonia-samples-csharp/src/AcrylicBlurWthoutDecoration/ViewModels/ViewModelBase.cs
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,6 @@ | ||
using CommunityToolkit.Mvvm.ComponentModel; | ||
|
||
namespace AcrylicBlurWthoutDecoration.ViewModels; | ||
|
||
public class ViewModelBase : ObservableObject { | ||
} |
44 changes: 44 additions & 0 deletions
44
avalonia-samples-csharp/src/AcrylicBlurWthoutDecoration/Views/MainWindow.axaml
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,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> |
7 changes: 7 additions & 0 deletions
7
avalonia-samples-csharp/src/AcrylicBlurWthoutDecoration/Views/MainWindow.axaml.cs
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,7 @@ | ||
using Avalonia.Controls; | ||
|
||
namespace AcrylicBlurWthoutDecoration.Views; | ||
|
||
public partial class MainWindow : Window { | ||
public MainWindow() => InitializeComponent(); | ||
} |
18 changes: 18 additions & 0 deletions
18
avalonia-samples-csharp/src/AcrylicBlurWthoutDecoration/app.manifest
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 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> |