ClippingWithViewbox.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="335.2" Width="401.6"
        x:Class="AvaloniaUI.ClippingWithViewbox"
        Title="ClippingWithViewbox">
    <Window.Resources>
        <GeometryGroup x:Key="clipGeometry" FillRule="NonZero">
            <EllipseGeometry RadiusX="75" RadiusY="50" Center="100,150"></EllipseGeometry>
            <EllipseGeometry RadiusX="100" RadiusY="25" Center="200,150"></EllipseGeometry>
            <EllipseGeometry RadiusX="75" RadiusY="130" Center="140,140"></EllipseGeometry>
        </GeometryGroup>
    </Window.Resources>

    <Grid>
        <Viewbox >
            <Button Width="350" Height="350" Clip="{StaticResource clipGeometry}" 
                    VerticalAlignment="Center" HorizontalAlignment="Center">A button</Button>
        </Viewbox>
    </Grid>
</Window>

ClippingWithViewbox.axaml.cs代码

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

namespace AvaloniaUI;

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

运行效果

image

 

posted on 2025-09-08 07:42  dalgleish  阅读(8)  评论(0)    收藏  举报