简体   繁体   English

Visual Studio Blend中的动画淡化

[英]Fading animation in Visual Studio Blend

I wish to change the actual content of my textblock. 我希望更改文本块的实际内容。 I know I can change it by using textblock.text = "new text" when an event is triggered. 我知道可以在触发事件时使用textblock.text = "new text"来更改它。 However, is there a way to make it change gradually, ie with a fade animation? 但是,是否有一种方法可以使其逐渐变化,即使用淡入淡出动画? I tried using Visual Studio Blend, and managed to make objects scale, and rotate, but I have not figured out how to make content of an element change/ apply animation when content of the element changes. 我尝试使用Visual Studio Blend,并设法使对象缩放和旋转,但是我还没有弄清楚如何更改元素的内容/在元素的内容更改时应用动画。

Here is a small example, which consists of a TextBox and a TextBlock. 这是一个小示例,由一个TextBox和一个TextBlock组成。 Each time you change the value in the TextBox, the content of the TextBlock fades out and in. 每次更改TextBox中的值时,TextBlock的内容就会淡出和淡入。

<StackPanel>
        <TextBox x:Name="txtSampleText" Margin="10" Text="This is a Sample Text"></TextBox>
        <TextBlock x:Name="tbMessage" Text="{Binding ElementName=txtSampleText, Path=Text, NotifyOnTargetUpdated=True}" Margin="10">
            <TextBlock.Triggers>
                <EventTrigger RoutedEvent="Binding.TargetUpdated">
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation Storyboard.TargetProperty="Opacity" Duration="0:0:1" From="1.0" To="0.0" />
                            <DoubleAnimation Storyboard.TargetProperty="Opacity" Duration="0:0:1" From="0.0" To="1.0"  />
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
            </TextBlock.Triggers>
        </TextBlock>
 </StackPanel>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM