WPF画箭头
1. 做上位机软件,经常会用到用箭头表示设备的连接次序,但是WPF似乎没有现成的箭头可用,所以只能通过Draw的方式自己画。其实可以通过VS Blend绘制,然后再导入到界面中,下面的这种方式也是这么实现的,只不过绘制出来之后直接可以以后用!
a. 首先导入Microsoft.Expression.Drawing.dll
b. 在界面中加入引用xmlns:ed="http://schemas.microsoft.com/expression/2010/drawing"
c. 在前端xaml文件中绘制箭头
<ed:LineArrow Grid.Column="1" Fill="#FFF4F4F5" HorizontalAlignment="Left" Height="0.878" Stroke="Black" VerticalAlignment="Center" MinWidth="50" RenderTransformOrigin="0.5,0.5"> <ed:LineArrow.RenderTransform> <TransformGroup> <ScaleTransform/> <SkewTransform/> <RotateTransform/> <TranslateTransform/> </TransformGroup> </ed:LineArrow.RenderTransform> </ed:LineArrow>
2. 在后台绘制直线(该部分转自LeeMacroFeng,https://www.cnblogs.com/LeeMacrofeng/p/7878898.html)
a. 通过Line画线
<Line X1="50" Y1="20" X2="400" Y2="20" Stroke="Red" StrokeThickness="10"></Line> <Line X1="10" Y1="40" X2="260" Y2="40" Stroke="Blue" StrokeThickness="6"></Line> <Line X1="10" Y1="60" X2="260" Y2="20" Stroke="Black" StrokeThickness="6"></Line> <Line X1="20" Y1="60" X2="360" Y2="60" Stroke="Green" StrokeThickness="3"></Line> <Line X1="30" Y1="80" X2="460" Y2="80" Stroke="Purple" StrokeThickness="1"></Line> <Line X1="40" Y1="90" X2="460" Y2="90" Stroke="Black" StrokeThickness="2"></Line> <Line X1="10" Y1="110" X2="360" Y2="110" StrokeDashArray="3" Stroke="RosyBrown" StrokeThickness="6"></Line> <Line X1="10" Y1="120" X2="360" Y2="120" StrokeDashArray="5" Stroke="RosyBrown" StrokeThickness="6"></Line> <Line X1="50" Y1="140" X2="460" Y2="140" StrokeEndLineCap="Flat" Stroke="Brown" StrokeThickness="6"></Line> <Line X1="40" Y1="155" X2="460" Y2="155" StrokeEndLineCap="Triangle" Stroke="Brown" StrokeThickness="8"></Line> <Line X1="200" Y1="10" X2="200" Y2="500" Stroke="Red" StrokeDashArray="10" StrokeThickness="9"></Line> <Line X1="40" Y1="170" X2="460" Y2="170" StrokeEndLineCap="Round" StrokeThickness="8"> <Line.Stroke> <LinearGradientBrush EndPoint="0,0.5" StartPoint="1,0.5"> <GradientStop Color="Blue"/> <GradientStop Offset="1"/> </LinearGradientBrush> </Line.Stroke> </Line>
b. 通过Rectangle画线
<Rectangle Grid.Column="1" Fill="#FFA89F9F" Width="1" Margin="4,3,4.6,3"/>
c. 通过Border画线