先看效果

 xaml代码

<UserControl x:Class="WPF控件测试.Control.Pipeline"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:WPF控件测试.Control"
mc:Ignorable="d"
d:DesignHeight="30" d:DesignWidth="800">
<Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup>
<VisualState x:Name="WELow">
<Storyboard RepeatBehavior="Forever">
<DoubleAnimation Duration="0:0:1" From="0" To="5"
Storyboard.TargetName="flow" Storyboard.TargetProperty="StrokeDashOffset"/>
</Storyboard>
</VisualState>
<VisualState x:Name="EELow">
<Storyboard RepeatBehavior="Forever">
<DoubleAnimation Duration="0:0:1" From="0" To="-5"
Storyboard.TargetName="flow" Storyboard.TargetProperty="StrokeDashOffset"/>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Border>
<Border.Background>
<LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
<GradientStop Color="#ffcbcbcb" Offset="0.9"/>
<GradientStop Color="#ffffffff" Offset="0.5"/>
<GradientStop Color="#ffcbcbcb" Offset="0.1"/>
</LinearGradientBrush>
</Border.Background>
<Border Margin="2" Name="bord">
<Line X1="0" Y1="0" X2="{Binding ActualWidth, RelativeSource={RelativeSource Self}}" Y2="0" Stroke="#CD5555" StrokeThickness="{Binding ElementName=bord,Path=ActualHeight}"
VerticalAlignment="Center" StrokeDashArray="5" Stretch="UniformToFill" StrokeDashCap="Round" StrokeStartLineCap="Round"
Opacity="0.7" Name="flow"/>
</Border>
</Border>
</Grid>
</UserControl>

cs代码

public partial class Pipeline : UserControl
{
public Pipeline()
{
InitializeComponent();
} public int Direction
{
get { return (int)GetValue(DirectionProperty); }
set { SetValue(DirectionProperty, value); }
} // Using a DependencyProperty as the backing store for Direction. This enables animation, styling, binding, etc...
public static readonly DependencyProperty DirectionProperty =
DependencyProperty.Register("Direction", typeof(int), typeof(Pipeline), new PropertyMetadata(default(int),new PropertyChangedCallback(OnDirectionChanged))); private static void OnDirectionChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
// VisualStateManager.GoToState(d as Pipeline, int.Parse(e.NewValue.ToString()!)==1? "WELow" : "EELow", false);
VisualStateManager.GoToState(d as Pipeline,int.Parse(e.NewValue.ToString()!) == 1 ? "WELow" : "EELow", false);
}
}

最新文章

  1. css文件内引用外部资源文件的相对路径
  2. NODE JS拼命吹,我就不喜欢. 别问为什么,直觉.
  3. 【Unity3D】Unity3D开发《我的世界》之一、创建一个面
  4. [luogu1402]酒店之王_网络流
  5. Java-NIO(九):管道 (Pipe)
  6. java 反射机制 观点
  7. Shell命令-文件及内容处理之vi、vim
  8. MySQL基础概述
  9. 对象引用对于非静态的字段、方法、属性Program.Print()是必需的
  10. OGG初始化之使用数据库实用程序加载数据
  11. Linux实验四报告
  12. spring中@Scope控制作用域
  13. Spring中初始化bean和销毁bean的时候执行某个方法的详解
  14. 前端框架(二)DIV多选复选框框的封装和MySql数据库存取
  15. C++ char float int string 之间的转换
  16. SystemID
  17. DbEntry 默认 主键ID为long
  18. Python 函数 -next()
  19. 每天一个linux命令:du 命令
  20. 【Unity】脚本选择打勾的勾选框隐藏

热门文章

  1. js数字取整的方法
  2. Oracle RAC单节点启停
  3. python读取Excel指定单元格的值
  4. 图片上传 加水印 以及GDI基本画图
  5. 八、常用Api
  6. RabbitMQ-01-使用Java进行简单消息发送与接收
  7. kunkun
  8. flask-基础篇03 请求钩子与上下文
  9. Window10上CLion极简配置教程
  10. postgresql 学习链接