C# 如何在WPF中创建闪烁的矩形笔划
在WPF中我的矩形下方:C# 如何在WPF中创建闪烁的矩形笔划,c#,wpf,storyboard,wpf-controls,C#,Wpf,Storyboard,Wpf Controls,在WPF中我的矩形下方: <Rectangle Margin="5,0" HorizontalAlignment="Left" Width="380" Height="25" Fill="LightYellow" Stroke="Orange" StrokeThickness="2" RadiusX="8" RadiusY="8"/> 当视图模型中的属性“StartBlinking”从false变为true时,我想开始闪烁几秒钟(然后停止)矩形笔划属性 我想用xaml而不是c
<Rectangle Margin="5,0" HorizontalAlignment="Left" Width="380" Height="25" Fill="LightYellow" Stroke="Orange" StrokeThickness="2" RadiusX="8" RadiusY="8"/>
当视图模型中的属性“StartBlinking”从false变为true时,我想开始闪烁几秒钟(然后停止)矩形笔划属性
我想用xaml而不是c代码实现故事板
我该怎么做
我尝试过这个,但没有成功:
<Rectangle Margin="5,0" HorizontalAlignment="Left" Width="380" Height="25" Fill="LightYellow" Stroke="Orange" StrokeThickness="2" RadiusX="8" RadiusY="8">
<Rectangle.Style>
<Style TargetType="{x:Type Rectangle}">
<Style.Resources>
<Storyboard x:Key="flashAnimation" >
<DoubleAnimation Storyboard.TargetProperty="Stroke" From="1" To="0" AutoReverse="True" Duration="0:0:0.5" RepeatBehavior="Forever" />
</Storyboard>
</Style.Resources>
</Style>
</Rectangle.Style>
</Rectangle>
我正在Visual Studio 2008中使用C#和.NET 3.5。您可以使用
DataTrigger
和情节提要
为笔划的不透明度
属性设置动画:
<Rectangle Margin="5,0" HorizontalAlignment="Left" Width="380" Height="25" Fill="LightYellow"
Stroke="Orange" StrokeThickness="2" RadiusX="8" RadiusY="8">
<Rectangle.Style>
<Style TargetType="Rectangle">
<Style.Triggers>
<DataTrigger Binding="{Binding StartBlinking}" Value="True">
<DataTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Stroke.(SolidColorBrush.Opacity)"
To="0" AutoReverse="True" Duration="0:0:0.5" RepeatBehavior="6x" />
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
<DataTrigger.ExitActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Stroke.(SolidColorBrush.Opacity)"
To="1" Duration="0:0:0.5" />
</Storyboard>
</BeginStoryboard>
</DataTrigger.ExitActions>
</DataTrigger>
</Style.Triggers>
</Style>
</Rectangle.Style>
</Rectangle>
我会试试的,谢谢。我还发现:但似乎.NET 3.5中不支持EasingPointKeyFrame,我如何使其适应.NET 3.5?为什么需要一个来使矩形闪烁…?我已经尝试了您的解决方案。当我从视图模型将StartBlinking属性设置为true时,它开始闪烁,但有两件事:1)它闪烁整个矩形体,而不是笔划,如果可能,我只希望笔划闪烁。2) 一旦开始闪烁,它就不会停止。如果您实现INotifyPropertyChanged接口并引发PropertyChanged事件,当您将StartBinging属性设置为false时,它就会停止。啊,好的,对不起,它有可能在启动x秒后自动停止?无需将属性设置为false。