我有一个带有背景图像的窗口。我想在单击按钮时将图像的不透明度属性从0更改为1,然后再在单击按钮时将图像的Opacity属性从1更改为0。我希望这种过渡能够顺利进行,所以才使用Storyboard。
以下内容可以使用,但是动画是一个无休止的循环,因此我正在努力地随意停止和恢复动画。如果可能,我想在没有代码支持的情况下执行此操作。建议?
<Window.Background>
<ImageBrush x:Name="imgBackground" ImageSource="Resources/Background.png" ></ImageBrush>
</Window.Background>
<Button Width="75" Height="21" Content="Go">
<Button.Triggers>
<EventTrigger RoutedEvent="Button.Click">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="imgBackground"
Storyboard.TargetProperty="Opacity" From="0" To="1"
BeginTime="0:0:0" AutoReverse="False" >
</DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Button.Triggers>
</Button>
看一下以下示例:https : //msdn.microsoft.com/zh-cn/library/ms753367(v=vs.110).aspx
您可能需要Duration属性和RepeatBehavior属性的组合。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句