在工作的项目中遇到一个需求,要虚线段实现设备的充放电效果,并且可以自由控制流动方向和停止,因此用后台代码实现流动效果控制。效果如下:
前台代码: Path对象是用Blend随便画的,可以是任意样式Path
<Window x:Class="WpfApp2.Control.FlowWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp2.Control"
mc:Ignorable="d"
Title="FlowWindow" Height="450" Width="600">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="100"></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal">
<Button Click="Button_Click" Width="50" Height="30" Content="充电" Margin="50,0,0,0"></Button>
<Button Click="Button_Click_1" Width="50" Height="30" Content="放电" Margin="50,0,0,0"></Button