C# 填充/背景颜色改变时,WPF闪烁
我想有一个椭圆填充“闪光”(立即变成白色,然后返回到新的颜色)每当数据绑定填充颜色的变化。到目前为止,我得到的是:C# 填充/背景颜色改变时,WPF闪烁,c#,wpf,colors,C#,Wpf,Colors,我想有一个椭圆填充“闪光”(立即变成白色,然后返回到新的颜色)每当数据绑定填充颜色的变化。到目前为止,我得到的是: <ctrls:NotifyEllipse Fill="{Binding Cluster.Brush, Converter={StaticResource CloneConverter}}" Width="10" Height="10" > <ctrls:NotifyEllipse.Style> <Style TargetType="{x:T
<ctrls:NotifyEllipse Fill="{Binding Cluster.Brush, Converter={StaticResource CloneConverter}}" Width="10" Height="10" >
<ctrls:NotifyEllipse.Style>
<Style TargetType="{x:Type ctrls:NotifyEllipse}">
<Style.Triggers>
<EventTrigger RoutedEvent="ctrls:NotifyEllipse.FillChanged">
<BeginStoryboard>
<Storyboard AutoReverse="True">
<ColorAnimation Storyboard.TargetProperty="(ctrls:NotifyEllipse.Fill).Color" To="White" Duration="0:0:1" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Style.Triggers>
</Style>
</ctrls:NotifyEllipse.Style>
</ctrls:NotifyEllipse>
加分:快速闪变为白色,不是立即闪变,而是保持原始颜色,直到达到全白色,然后慢慢从白色变为新颜色,这将是理想的解决方案,但我担心这将需要大量自定义动画代码。如上所述的闪光灯就足够了。只需从
白色开始彩色动画即可:
<Storyboard>
<ColorAnimation Storyboard.TargetProperty="Fill.Color"
From="White" Duration="0:0:1" />
</Storyboard>
就这么简单?我真的花了一天时间来解决这个问题。。。非常感谢
<Storyboard>
<ColorAnimation Storyboard.TargetProperty="Fill.Color"
From="White" Duration="0:0:1" />
</Storyboard>
public class NotifyEllipse : Shape
{
static NotifyEllipse()
{
FillProperty.AddOwner(typeof(NotifyEllipse), new FrameworkPropertyMetadata(
(o, e) =>
{
if (e.NewValue != e.OldValue)
{
((NotifyEllipse)o).RaiseEvent(new RoutedEventArgs(FillChangedEvent));
}
}));
}
public static readonly RoutedEvent FillChangedEvent =
EventManager.RegisterRoutedEvent(
"FillChanged", RoutingStrategy.Bubble,
typeof(RoutedEventHandler), typeof(NotifyEllipse));
public event RoutedEventHandler FillChanged
{
add { AddHandler(FillChangedEvent, value); }
remove { RemoveHandler(FillChangedEvent, value); }
}
protected override Geometry DefiningGeometry
{
get { return new EllipseGeometry(new Rect(RenderSize)); }
}
}