FillRule为填充规则的意思,它有两个属性值,EvenOdd,Nonzero,如下表:
FillRule | 属性值 | 使用方法 |
EvenOdd(默认值) | 具有穿透效果 | |
Nonzero | 无穿透效果 |
看下效果吧,GemetryGroup使用 EventOdd属性时的代码如下:
<Window x:Class="Drawing.GroupedShapes"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="GroupedShapes" Height="300" Width="300"
>
<Canvas>
<TextBlock Canvas.Top="50" Canvas.Left="20" FontSize="25" FontWeight="Bold">Hello There</TextBlock>
<Path Fill="Yellow" Stroke="Blue" Margin="5" Canvas.Top="10" Canvas.Left="10" >
<Path.Data>
<GeometryGroup FillRule="EvenOdd">
<RectangleGeometry Rect="0 0 100 100"></RectangleGeometry>
<EllipseGeometry Center="50 50" RadiusX="35" RadiusY="25"></EllipseGeometry>
</GeometryGroup>
</Path.Data>
</Path>
</Canvas>
</Window>
运行效果:
明显文本可以透过椭圆。再看看属性为Nonzero
<Window x:Class="Geometry.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
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"
xmlns:local="clr-namespace:Geometry"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Window.Resources>
<GeometryGroup x:Key="Geometry">
<RectangleGeometry Rect="0,0 100,100"></RectangleGeometry>
<EllipseGeometry Center="150,50" RadiusX="35" RadiusY="25"></EllipseGeometry>
</GeometryGroup>
</Window.Resources>
<Canvas>
<TextBlock Canvas.Top="50" Canvas.Left="20" FontSize="25" FontWeight="Bold">Hello There</TextBlock>
<Path Fill="Yellow" Stroke="Blue" Margin="5" Canvas.Top="10" Canvas.Left="10">
<Path.Data>
<GeometryGroup FillRule="Nonzero">
<RectangleGeometry Rect="0,0 100,100"></RectangleGeometry>
<EllipseGeometry Center="50,50" RadiusX="35" RadiusY="25"></EllipseGeometry>
</GeometryGroup>
</Path.Data>
</Path>
</Canvas>
</Window>
运行效果:
文本没有穿透椭圆,所以想要有穿透效果的就用EvenOdd吧。