烨哥 发表于 2023-8-14 16:14:21

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()效果图: 可以流动的虚线

 代码实例:页面代码
 后台代码:
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绑定赋值。
来源:https://www.cnblogs.com/wjygxjz/archive/2023/08/14/17628834.html
免责声明:由于采集信息均来自互联网,如果侵犯了您的权益,请联系我们【E-Mail:cb@itdo.tech】 我们会及时删除侵权内容,谢谢合作!
页: [1]
查看完整版本: WPF图形控件使用之-Line线控件使用