如何将此 TextBlock 淡入触发器转换为样式 [英] How can I convert this TextBlock fade-in trigger to a Style
本文介绍了如何将此 TextBlock 淡入触发器转换为样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
此 XAML 使文本在出现时淡入.
This XAML makes text fade in when it appears.
我想将此功能放入样式中.
I would like to put this functionality into a Style.
但是,由于样式不知道哪个元素将使用它,所以我应该为TargetName"输入什么?
However, but what do I put in for the "TargetName" since the style doesn't know which element is going to be using it?
如何将此淡入效果转换为样式?
How can I convert this fade-in effect to a style?
<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="0.0" To="1.0" Duration="0:0:3"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</TextBlock.Triggers>
</TextBlock>
推荐答案
您不必使用 TargetName.这有效:
You don't have to use TargetName. This works:
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Page.Resources>
<Style TargetType="TextBlock">
<Style.Triggers>
<EventTrigger RoutedEvent="TextBlock.Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Storyboard.TargetProperty="(TextBlock.Opacity)"
From="0.0" To="1.0" Duration="0:0:3"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Style.Triggers>
</Style>
</Page.Resources>
<Grid>
<TextBlock Name="Message" Text="This is a test.">
</TextBlock>
</Grid>
</Page>
这篇关于如何将此 TextBlock 淡入触发器转换为样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文