我想用Datatrigger开始一个Storyboard。现在我有一个适合我的Eventtrigger解决方案。这是我的代码:
<Rectangle Width="100" Height="100">
<Rectangle.Fill>
<ImageBrush x:Name="test" ImageSource="Tulips.jpg"></ImageBrush>
</Rectangle.Fill>
<Rectangle.Triggers>
<EventTrigger RoutedEvent="Rectangle.Loaded">
<BeginStoryboard>
<Storyboard>
<ObjectAnimationUsingKeyFrames
Storyboard.TargetProperty="(ImageSource)"
Storyboard.TargetName="test">
<DiscreteObjectKeyFrame KeyTime="0:0:1">
<DiscreteObjectKeyFrame.Value>
<BitmapImage UriSource="Tulips.jpg" />
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
<DiscreteObjectKeyFrame KeyTime="0:0:2">
<DiscreteObjectKeyFrame.Value>
<BitmapImage UriSource="Chrysanthemum.jpg" />
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Rectangle.Triggers>
</Rectangle>
现在,如果Code Behind File中的变量设置为特定值,我想用数据触发器启动故事板。我怎么能这样做?