WPF:如何将简单的动画应用于标签?
我有一个标签,里面有图像。我想应用一个简单的动画:更改不透明度属性以在加载标签后(或当可见或其他什么时)实现淡入效果
但这不起作用:
<Label ContentTemplate="{DynamicResource ImageLabelDataTemplate}" Canvas.Left="36" Canvas.Top="394" Height="116" Name="PreviousVirtualButton" Width="100" Visibility="Hidden">
<Label.Style>
<Style TargetType="Label">
<Style.Triggers>
<Trigger Property="IsVisible" Value="True">
<Trigger.EnterActions>
<BeginStoryboard>
<Storyboard TargetProperty="Opacity">
<DoubleAnimation Storyboard.TargetProperty="Opacity" From="0" To="1" Duration="0:0:5" />
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
</Trigger>
</Style.Triggers>
</Style>
</Label.Style>
</Label>
我想看看标签如何正在屏幕上淡入。
提前致谢。
I have a label with an image inside. I'd like to apply a simple animation: changing the opacity property for achieving a fade-in effect after the label is loaded (or when is visible or whatever)
But this doesn't work:
<Label ContentTemplate="{DynamicResource ImageLabelDataTemplate}" Canvas.Left="36" Canvas.Top="394" Height="116" Name="PreviousVirtualButton" Width="100" Visibility="Hidden">
<Label.Style>
<Style TargetType="Label">
<Style.Triggers>
<Trigger Property="IsVisible" Value="True">
<Trigger.EnterActions>
<BeginStoryboard>
<Storyboard TargetProperty="Opacity">
<DoubleAnimation Storyboard.TargetProperty="Opacity" From="0" To="1" Duration="0:0:5" />
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
</Trigger>
</Style.Triggers>
</Style>
</Label.Style>
</Label>
I'd like to see how the label is fading in on the screen.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
试试这个:
Try this:
如果您删除
Visibility="Hidden"
,它将起作用(假设您希望它在加载时淡入)。否则,当您希望它开始淡入时,请在代码隐藏中将Visibility
设置为Visibility.Visible
。另外,请确保在 ContentTemplate 中有可见的内容。If you remove the
Visibility="Hidden"
, it will work (assuming you want it to fade in when it loads). Otherwise, set theVisibility
toVisibility.Visible
from code-behind when you want it to start fade in. Also, make sure that in the ContentTemplate you have something visible.您是否在代码中的某处设置了可见的标签?您必须将其设置为可见才能触发动画。
C# 示例:
previousVirtualButton.Visibility = System.Windows.Visibility.Visible;
Are you setting the label visible in your code somewhere? You have to set it to be visible in order for the animation to trigger.
C# example:
previousVirtualButton.Visibility = System.Windows.Visibility.Visible;