WPF图形控件使用之-Line线控件使用
在项目中有的时候可能会用的画虚线或者设置线的流动效果,这个时候可能会使用到线控件。
|
属性
|
说明
|
描述
|
|
X1
|
起始x轴坐标
|
X1="10"
|
|
Y1
|
起始Y轴坐标
|
Y1="10"
|
|
X2
|
结束X轴坐标
|
X2="100"
|
|
Y2
|
结束Y轴坐标
|
Y2="100"
|
|
Stroke
|
线条颜色
|
Stroke="Red"
|
|
StrokeThickness
|
线条粗细
|
StrokeThickness="2"
|
|
StrokeDashArray
|
设置虚线
管道流动效果可以用虚线表示
可以用这个属性做流动线效果。
|
StrokeDashArray="3,1,2,5",(规律是第一位可视,第二位隐藏,第三位可视,第四位隐藏)循环
StrokeDashArray="3,1,2",(规律是第一位可视,第二位隐藏,第三位可视,第四位隐藏)循环
|
|
StrokeDashOffset="1"
|
StrokeDashOffset="1"
|
通过后台代码循环设置属性值1-N,线就流动起来了
|
|
StrokeDashCap
|
虚线段的两端样式(向外延伸三角、半圆、方形)
|
StrokeDashCap="Round" Round(圆线头)Square(矩形),Triangle(三角)图形是在线的外面添加。
|
|
StrokeEndLineCap
|
设置线的结尾样式调整 |
StrokeEndLineCap="Round" Round(圆线头)Square(矩形),Triangle(三角)图形是在线的外面添加。
|
|
StrokeStartLineCap
|
设置显得开头样式调整
|
StrokeStartLineCap="Round"
|
|
|
|
|
|
Fill
|
填充色,没有用处,继承至父类过来的
|
Fill="Orange"
|
|
HorizontalAlignment
|
|
HorizontalAlignment="Left"
|
|
VerticalAlignment
|
|
VerticalAlignment="Top"
|
|
Panel.ZIndex
|
|
Panel.ZIndex="1"
|
|
StrokeMiterLimit
|
(交叉点锐角向外延伸距离)设置尖角的范围有多大
|
0-10
|
|
StrokeLineJoin
|
(交叉点的锐角样式)设置尖角形状
|
Round(圆角),Bevel( ),Miter()
|
效果图: 可以流动的虚线

代码实例:页面代码
<Line x:Name="ln" X1="10" Y1="10" X2="100" Y2="100"
Stroke="Red" StrokeThickness="2" StrokeDashArray="3,1,2,5"
StrokeDashCap="Triangle" StrokeEndLineCap="Round" StrokeStartLineCap="Round"
Fill="Orange" HorizontalAlignment="Left" VerticalAlignment="Top"
Panel.ZIndex="1"
/>
后台代码:
int number = 1;
Task.Run(() =>
{
while (true)
{
if (number == 10)
number = 1;
Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
ln.StrokeDashOffset = number;
}));
number++;
Thread.Sleep(300);
}
});
StrokeDashOffset属性可以通过MVVM绑定赋值。

浙公网安备 33010602011771号