【问题标题】:How can I convert this TextBlock fade-in trigger to a Style如何将此 TextBlock 淡入触发器转换为样式
【发布时间】:2010-10-29 05:20:43
【问题描述】:

此 XAML 使文本在出现时淡入。

我想将此功能放入样式中。

但是,由于样式不知道要使用哪个元素,我应该为“TargetName”添加什么?

如何将此淡入效果转换为样式?

<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>

【问题讨论】:

    标签: wpf xaml styles textblock


    【解决方案1】:

    您不必使用 TargetName。这有效:

    <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>
    

    【讨论】:

      猜你喜欢
      • 2012-02-27
      • 2019-04-08
      • 2015-03-27
      • 1970-01-01
      • 2015-09-10
      • 2016-11-16
      • 1970-01-01
      • 1970-01-01
      • 2020-09-13
      相关资源
      最近更新 更多