Dav*_*ton 10 c# wpf xaml mvvm storyboard
目前我有一个Image
我加载时脉冲.我想在更改图像的可见性时激活故事板.但我认为Image.Triggers
必须如此EventTriggers
.
我需要涉及哪个事件?
<Image.Triggers>
<EventTrigger RoutedEvent="Image.Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="MandateErrorImage"
Storyboard.TargetProperty="Opacity"
From="1.0" To="0.1" Duration="0:0:0.5"
AutoReverse="True" RepeatBehavior="0:0:2" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Image.Triggers>
Run Code Online (Sandbox Code Playgroud)
在WPF中有一个事件UIElement.IsVisibleChanged
但是是CLR事件,而不是路由事件,因此EventTrigger
无法使用.
在这种情况下使用IsVisible
属性DataTrigger
如下:
<Window.Resources>
<Style x:Key="AnimationImageStyle" TargetType="{x:Type Image}">
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=IsVisible}"
Value="True">
<DataTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Opacity"
From="1.0" To="0.1"
Duration="0:0:0.5"
AutoReverse="True"
RepeatBehavior="0:0:2" />
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
</DataTrigger>
</Style.Triggers>
</Style>
</Window.Resources>
<Grid>
<Image Name="TestImage"
Style="{StaticResource AnimationImageStyle}"
Source="Enter.jpg"
Width="400"
Height="400" />
</Grid>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
8827 次 |
最近记录: |