我试图在wpf和c#中实现对图像的淡出效果
<Image.Triggers>
<EventTrigger RoutedEvent="Image.Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="imgSlot1"
Storyboard.TargetProperty="Opacity"
From="1.0" To="0.0" Duration="0:0:1"
AutoReverse="True" RepeatBehavior="Forever"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
使用此代码,我看到我的图像闪烁,这没关系,但为什么我将RepeatBehavior改为&#34; 1x&#34;或&#34; 0:0:1&#34;和自动反转到&#34;错误&#34; (我必须在我的图像上创建一个淡出淡出的效果)没有任何作用?
答案 0 :(得分:1)
<Image.Triggers>
<EventTrigger RoutedEvent="Image.Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="imgSlot1"
Storyboard.TargetProperty="Opacity"
From="1.0" To="0.0" Duration="0:0:1"
AutoReverse="False" RepeatBehavior="1x"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Image.Triggers>
但是,我不确定您是否希望在Image.Loaded事件上发生这种情况。并且记住,即使没有故事板,您也可以轻松地从C#或VB控制它,类似于以下内容:
DoubleAnimation fadeoutAnimation = new DoubleAnimation();
fadeoutAnimation.Duration = TimeSpan.FromSeconds(1.0d);
fadeoutAnimation.From = 1.0d;
fadeoutAnimation.To = 0.0d;
imgSlot1.BeginAnimation(Image.OpacityProperty, fadeoutAnimation);
希望这有帮助!