【发布时间】:2012-03-26 14:13:13
【问题描述】:
我正在使用 MVVM 设计模式,并且不想在我的代码中包含太多代码。用 XAML 和 C# 编码。
当用户保存新记录时,我希望“记录已保存”出现在文本块中,然后消失。
这是我想做的事情:
<TextBlock Name="WorkflowCreated" Text="Record saved">
<TextBlock.Triggers>
<DataTrigger Binding="{Binding Path=NewWorkflowCreated}">
<DataTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="WorkflowCreated"
Storyboard.TargetProperty="(TextBlock.Opacity)"
From="1.0" To="0.0" Duration="0:0:3"/>
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
</DataTrigger>
</TextBlock.Triggers>
所以当在视图模型中更改 NewWorkflowCreated 时,它会触发动画,不幸的是这不起作用。我也试过这个:
<TextBlock Name="Message" Text="This is a test.">
<TextBlock.Triggers>
<EventTrigger RoutedEvent="TextBlock.Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="Message"
Storyboard.TargetProperty="(TextBlock.Opacity)"
From="1.0" To="0.0" Duration="0:0:3"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</TextBlock.Triggers>
</TextBlock>
任何帮助将不胜感激。也许在 View 模型中有需要代码的地方?
【问题讨论】:
标签: wpf xaml data-binding animation mvvm