官方的Polygon并没有实现FillRule,但是大家可以自己扩展,这里我用官方Path替代。

InsideOutsideFill.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="479" Width="462"
        x:Class="AvaloniaUI.InsideOutsideFill"
        Title="InsideOutsideFill">
    <Viewbox HorizontalAlignment="Left">
        <Canvas Width="200" Height="400" >
            <Polygon Stroke="Blue" StrokeThickness="1" Fill="Yellow" Canvas.Left="10"
              Points="15,200 68,70 110,200 0,125 135,125" >
            </Polygon>
            
            <Path Stroke="Blue" StrokeThickness="1" Fill="Yellow" Canvas.Left="10" Canvas.Top="175">
                <Path.Data>
                    <GeometryGroup FillRule="NonZero">
                        <PathGeometry>
                            <PathFigure StartPoint="15,200" IsClosed="True">
                                <LineSegment Point="68,70"/>
                                <LineSegment Point="110,200"/>
                                <LineSegment Point="0,125"/>
                                <LineSegment Point="135,125"/>
                            </PathFigure>
                        </PathGeometry>
                    </GeometryGroup>
                </Path.Data>
            </Path>
            
        </Canvas>
    </Viewbox>
</Window>

InsideOutsideFill.axaml.cs代码

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

namespace AvaloniaUI;

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

运行效果

image

 

posted on 2025-09-03 13:25  dalgleish  阅读(9)  评论(0)    收藏  举报