Reflection.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="208.8" Width="491.2" Background="LightSteelBlue"
        x:Class="AvaloniaUI.Reflection"
        Title="Reflection">
    <Grid Margin="10" Grid.IsSharedSizeScope="True" VerticalAlignment="Center">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" SharedSizeGroup="Row"></RowDefinition>
            <RowDefinition SharedSizeGroup="Row"></RowDefinition>
        </Grid.RowDefinitions>
        
        <TextBox Name="txt" FontSize="30">Here is some reflected text</TextBox>
        
        <Rectangle Grid.Row="1" RenderTransformOrigin="100%,50%">
            <Rectangle.Fill>
                <VisualBrush Visual="{Binding #txt}"></VisualBrush>
            </Rectangle.Fill>

            <Rectangle.OpacityMask>
                <LinearGradientBrush StartPoint="0,0" EndPoint="0%,100%">
                    <GradientStop Offset="0.3" Color="Transparent"></GradientStop>
                    <GradientStop Offset="1" Color="#44000000"></GradientStop>
                </LinearGradientBrush>
            </Rectangle.OpacityMask>

            <Rectangle.RenderTransform>
                <ScaleTransform ScaleY="-1"></ScaleTransform>
            </Rectangle.RenderTransform>
        </Rectangle>
    </Grid>
</Window>

Reflection.axaml.cs代码

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

namespace AvaloniaUI;

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

运行效果

image

 

posted on 2025-09-05 10:24  dalgleish  阅读(9)  评论(0)    收藏  举报