WPF學習筆記之路徑繪圖
效果如下:
界面代碼如下:
<Window x:Class="Graphic_00.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:Graphic_00"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Window.Resources>
<GeometryGroup x:Key="GeometryNonZero" FillRule="Nonzero">
<EllipseGeometry RadiusX="50" RadiusY="50" Center="65,60"/>
<EllipseGeometry RadiusX="30" RadiusY="30" Center="65,60"/>
</GeometryGroup>
<GeometryGroup x:Key="GeometryGroupEvenOdd" FillRule="EvenOdd">
<EllipseGeometry RadiusX="50" RadiusY="50" Center="65,60"/>
<EllipseGeometry RadiusX="30" RadiusY="30" Center="65,60"/>
</GeometryGroup>
</Window.Resources>
<Border Name="myBorder" BorderBrush="Blue" BorderThickness="2" Margin="5,5,5,5" Background="LightGray">
<Grid ShowGridLines="True">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock Text="GeometryNonZeroFontSize="20" HorizontalAlignment="Center" Width="200" VerticalAlignment="Center"/>
<Path Fill="Red" Stroke="Black" StrokeThickness="2" Data="{StaticResource GeometryNonZero}"/>
</StackPanel>
<StackPanel Grid.Row="0" Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock Text="GeometryGroupEvenOdd" FontSize="20" HorizontalAlignment="Center" Width="200" VerticalAlignment="Center"/>
<Path Fill="Blue" Stroke="Black" StrokeThickness="2" Data="{StaticResource GeometryGroupEvenOdd }"/>
</StackPanel>
<StackPanel Grid.Row="1" Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock Text="GeometryNonZero" FontSize="20" HorizontalAlignment="Center" Width="200" VerticalAlignment="Center"/>
<Path Fill="Green" Stroke="Black" StrokeThickness="2" Data="{StaticResource GeometryNonZero }"/>
</StackPanel>
<StackPanel Grid.Row="1" Grid.Column="0" HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock Text="GeometryGroupEvenOdd" FontSize="20" HorizontalAlignment="Center" Width="200" VerticalAlignment="Center"/>
<Path Fill="Yellow" Stroke="Black" StrokeThickness="2" Data="{StaticResource GeometryGroupEvenOdd }"/>
</StackPanel>
</Grid>
</Border>
</Window>