Textbox Text-Color Animation

2019-09-05 23:41发布

Is it possible to animate just the part of the value of textbox/label. For example, txt1.text = "This is a Sample";. then I want to animate the word "Sample" to change its color/opacity etc. If you get what i mean. If it is possible please demonstrate the code Thanks!

1条回答
唯我独甜
2楼-- · 2019-09-06 00:22

I think you can't do it with a TextBox as its text has no formatting options. Not sure if the Label allows it, but the TextBlock might help you:

<TextBlock>
  <TextBlock.Triggers>
    <EventTrigger RoutedEvent="Loaded">
      <BeginStoryboard>
        <Storyboard>
          <ColorAnimation Storyboard.TargetName="scb01"
                          Storyboard.TargetProperty="Color"
                          From="White"
                          To="Black"
                          Duration="0:0:0.5"
                          AutoReverse="True"
                          RepeatBehavior="Forever" />
        </Storyboard>
      </BeginStoryboard>
    </EventTrigger>
  </TextBlock.Triggers>
  One <Run>
    <Run.Foreground>
      <SolidColorBrush x:Name="scb01"
                        Color="Red" />
    </Run.Foreground>
    Two</Run> Three
</TextBlock>
查看更多
登录 后发表回答