CombiningShapes.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="481" Width="341"
        x:Class="AvaloniaUI.CombiningShapes"
        Title="CombiningShapes">
    <Window.Resources>
        <RectangleGeometry x:Key="rect" Rect="0,0,100,100"></RectangleGeometry>
        <EllipseGeometry x:Key="ellipse" Center="85,50" RadiusX="65" RadiusY="35"></EllipseGeometry>
    </Window.Resources>

    <Grid Margin="5" RowDefinitions="auto,auto,auto,auto" ColumnDefinitions="auto,auto">
        <Grid.Styles>
            <Style Selector="TextBlock">
                <Setter Property="FontSize" Value="16"/>
            </Style>
        </Grid.Styles>
        <Path Fill="Yellow" Stroke="Blue" StrokeThickness="1" Margin="5">
            <Path.Data>
                <CombinedGeometry GeometryCombineMode="Union"      
                                  CombinedGeometry.Geometry1="{StaticResource rect}"
                                  CombinedGeometry.Geometry2="{StaticResource ellipse}">
                </CombinedGeometry>
            </Path.Data>
        </Path>
        <TextBlock Grid.Column="1" Margin="10" VerticalAlignment="Center">Union</TextBlock>

        <Path Grid.Row="1" Fill="Yellow" Stroke="Blue" StrokeThickness="1" Margin="5">
            <Path.Data>
                <CombinedGeometry GeometryCombineMode="Intersect"
                                  CombinedGeometry.Geometry1="{StaticResource rect}"
                                  CombinedGeometry.Geometry2="{StaticResource ellipse}">
                </CombinedGeometry>
            </Path.Data>
        </Path>
        <TextBlock Grid.Row="1" Grid.Column="1" Margin="10" VerticalAlignment="Center">Intersect</TextBlock>

        <Path Grid.Row="2" Fill="Yellow" Stroke="Blue" StrokeThickness="1" Margin="5">
            <Path.Data>
                <CombinedGeometry GeometryCombineMode="Xor"
                                  CombinedGeometry.Geometry1="{StaticResource rect}"
                                  CombinedGeometry.Geometry2="{StaticResource ellipse}">
                </CombinedGeometry>
            </Path.Data>
        </Path>
        <TextBlock Grid.Row="2" Grid.Column="1" Margin="10" VerticalAlignment="Center">Xor</TextBlock>

        <Path Grid.Row="3" Fill="Yellow" Stroke="Blue" StrokeThickness="1" Margin="5">
            <Path.Data>
                <CombinedGeometry GeometryCombineMode="Exclude"
                                  CombinedGeometry.Geometry1="{StaticResource rect}"
                                  CombinedGeometry.Geometry2="{StaticResource ellipse}">
                </CombinedGeometry>
            </Path.Data>
        </Path>
        <TextBlock Grid.Row="3" Grid.Column="1" Margin="10" VerticalAlignment="Center">Exclude</TextBlock>
    </Grid>
</Window>

CombiningShapes.axaml.cs代码

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

namespace AvaloniaUI;

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

运行效果

image

 

posted on 2025-09-06 13:39  dalgleish  阅读(10)  评论(0)    收藏  举报