WPF形状

  1. 不设置尺寸则填充满容器
<Window x:Class="项目10.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:sys="clr-namespace:System;assembly=mscorlib"
        xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
        xmlns:custom="clr-namespace:CustomBehaviorsLibrary;assembly=CustomBehaviorsLibrary"
        xmlns:local="clr-namespace:项目10"
        mc:Ignorable="d"
        Title="MainWindow" Width="500" Height="400"  WindowStartupLocation="CenterScreen">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"></RowDefinition>
            <RowDefinition Height="*"></RowDefinition>
        </Grid.RowDefinitions>
        <Rectangle Margin="15" Stroke="Black" RadiusX="15" RadiusY="15"></Rectangle>
        <Ellipse Grid.Row="1" Margin="15" Fill="Red" Stretch="Fill"></Ellipse>
    </Grid>
</Window>

  1. 使用Canvas可以缩放图形
<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="*"></RowDefinition>
        <RowDefinition Height="*"></RowDefinition>
    </Grid.RowDefinitions>
    <TextBlock>The First row of Grid</TextBlock>
    <Viewbox Grid.Row="1" HorizontalAlignment="Left">
        <Canvas Height="200" Width="450">
            <Ellipse Fill="Yellow" Stretch="Fill" Stroke="Blue" Canvas.Left="10" Canvas.Top="50"
                     Height="100" Width="150" HorizontalAlignment="Left"/>
            <Rectangle Stroke="Red" Width="250" Height="150" HorizontalAlignment="Right"
                       Canvas.Right="25" Canvas.Bottom="10"/>
        </Canvas>
    </Viewbox>
</Grid>

  1. 直线、多段线和多边形
<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="*"></RowDefinition>
        <RowDefinition Height="3*"></RowDefinition>
    </Grid.RowDefinitions>
    <TextBlock>The First row of Grid</TextBlock>
    <Viewbox Grid.Row="1" HorizontalAlignment="Left">
        <Canvas Height="200" Width="450">
            <Line Stroke="Red"  X1="15" Y1="15" X2="65" Y2="15" Canvas.Left="56"></Line>
            <Polyline Stroke="Blue" Points="5,5 150,200 20,180 5,5"></Polyline>
            <Polygon Points="5,5 150,200 20,180" Canvas.Left="250" Fill="Pink"></Polygon>
        </Canvas>
    </Viewbox>
</Grid>

  1. 画笔的一些属性
<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="*"></RowDefinition>
        <RowDefinition Height="3*"></RowDefinition>
    </Grid.RowDefinitions>
    <TextBlock>The First row of Grid</TextBlock>
    <Viewbox Grid.Row="1" HorizontalAlignment="Left">
        <Canvas Height="200" Width="450">
            <Line StrokeThickness="5" StrokeEndLineCap="Triangle" StrokeStartLineCap="Round" Stroke="Red"  X1="15" Y1="15" X2="65" Y2="15" Canvas.Left="56"></Line>
            <Polyline StrokeThickness="5" StrokeDashArray="3 2" Stroke="Blue" Points="5,5 150,200 20,180 5,5"></Polyline>
            <Polygon Points="5,5 150,200 20,180" Canvas.Left="250" Fill="Pink"></Polygon>
        </Canvas>
    </Viewbox>
</Grid>