TransparentBackground.axaml代码
<Window xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" Height="300" Width="300" SystemDecorations="None" TransparencyLevelHint="AcrylicBlur,Transparent" Background="Transparent" x:Class="AvaloniaUI.TransparentBackground" Title="TransparentBackground" PointerPressed="Window_PointerPressed"> <Window.Background> <ImageBrush Source="avares://AvaloniaUI/Resources/Images/shapes.png" Stretch="UniformToFill" Opacity="0.7"/> </Window.Background> <Grid RowDefinitions="*,*,*,*"> <Button Margin="20">A Sample Button</Button> <Button Margin="20" Grid.Row="2" Click="cmdClose_Click"> Close </Button> </Grid> </Window>
TransparentBackground.axaml.cs代码
using Avalonia;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Markup.Xaml;
namespace AvaloniaUI;
public partial class TransparentBackground : Window
{
public TransparentBackground()
{
InitializeComponent();
}
private void Window_PointerPressed(object? sender, PointerPressedEventArgs e)
{
if (e.GetCurrentPoint(this).Properties.IsLeftButtonPressed)
BeginMoveDrag(e);
}
private void cmdClose_Click(object? sender, RoutedEventArgs e)
{
Close();
}
}
运行效果

浙公网安备 33010602011771号