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吧。