基本知识(宽高未设置):
<Ellipse Fill="yellow" Stroke="blue" Stretch="FIll"/>
<Rectangle Fill="yellow" Stroke="blue" Stretch="FIll"/>
比较重要的的几个属性
Stretch: Fill None Uniform UniformToFill
通常绘图是在Canvas中进行的,但是由于其使用的是坐标,故在size改变时,容易产生变形。其中一个解决方法是将Canvas放置于ViewBox中。
直线
<Line Stroke="Blue" X1="" Y1="" X2="" Y2=""/>对于直线,Fill不起作用,设置Stroke即可
<Polyline Stroke="blue" Points="5 100 15 200"/>从(5,100)到(15,200)的直线
<polygon Stroke="" Points=""/>其与Polyline相似,只是最后一点会与首点相连,其余Polyline都有一个FillRule属性,用于填充。
虚线可以使用StrokeDashArray去实现
变换:
RenderTransfrom和LayoutTransfrom(比较少用)
RotateTransfrom Angle旋转角度 RenderTransfromOrigin旋转中心
画刷:
<LinearGradientBrush/>
<RadialGradientBursh/>
<ImageBrush/>
介绍VisualBrush
<WrapPanel Orientation="Vertical">
<TextBox x:Name="txt" Width="126" Height="36"/>
<Rectangle Width="126" Height="36" RenderTransformOrigin=".5,.5">
<Rectangle.Fill>
<VisualBrush Visual="{Binding ElementName=txt}"/>
</Rectangle.Fill>
<Rectangle.RenderTransform>
<RotateTransform Angle="180"/>
</Rectangle.RenderTransform>
<Rectangle.OpacityMask>
<LinearGradientBrush StartPoint="1,0" EndPoint="0,0">
<GradientStop Offset="1" Color="Transparent"/>
<GradientStop Offset="0" Color="Blue"/>
</LinearGradientBrush>
</Rectangle.OpacityMask>
</Rectangle>
</WrapPanel>
效果