Transparency.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="385" Width="450"
        x:Class="AvaloniaUI.Transparency"
        Title="Transparency">
    <StackPanel Margin="5">
        <StackPanel.Background>
            <ImageBrush Source="avares://AvaloniaUI/Resources/Images/celestial.jpg" Opacity="0.7"/>
        </StackPanel.Background>

        <Button Foreground="White" FontSize="16" Margin="10"
                BorderBrush="White" Background="#60AA4030"    
                Padding="20">A Semi-Transparent Button</Button>

        <Label Margin="10" FontSize="18" FontWeight="Bold" Foreground="White">Some Label Text</Label>

        <TextBox Margin="10" Background="#AAAAAAAA" Foreground="White" BorderBrush="White">A semi-transparent text box</TextBox>

        <Button Margin="10" Padding="25" BorderBrush="White" Width="350">
            <Button.Background>
                <ImageBrush Source="avares://AvaloniaUI/Resources/Images/happyface.jpg" Opacity="0.6"
                            TileMode="Tile" Stretch="Fill" DestinationRect="0%,0%,10%,40%"/>
            </Button.Background>        
        </Button>

        <TextBlock Foreground="#75FFFFFF"  TextAlignment="Center"
                  FontSize="30"
                  FontWeight="Bold" TextWrapping="Wrap" >Semi-Transparent Layers</TextBlock>
    </StackPanel>
</Window>

Transparency.axaml.cs代码

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

namespace AvaloniaUI;

public partial class Transparency : Window
{
    public Transparency()
    {
        InitializeComponent();
    }
}

运行效果

image

 

posted on 2025-09-05 09:37  dalgleish  阅读(17)  评论(0)    收藏  举报