我需要一个在UWP或Winui中的文本块上动画前景刷的示例

发布于 2025-01-22 22:37:16 字数 361 浏览 0 评论 0原文

我想在某些东西变化时为文本的颜色做动画。我找不到任何代码示例(除了使用故事板的示例,我想避免的示例)。我发现了这一点:

  var animation = _compositor.CreateColorKeyFrameAnimation(); 
  animation.InsertKeyFrame(0.0f, Color.FromArgb(255, 0, 255, 0));
  animation.InsertKeyFrame(1.0f, Colors.Purple);
  targetVisual.Brush.StartAnimation("Color", animation);

但是不知道如何将这个概念连接到文本块上普通的旧前景刷。

I want to animate the color of text when something changes. I can't find any code examples (other than ones that use the Storyboard, which I want to avoid). I found this:

  var animation = _compositor.CreateColorKeyFrameAnimation(); 
  animation.InsertKeyFrame(0.0f, Color.FromArgb(255, 0, 255, 0));
  animation.InsertKeyFrame(1.0f, Colors.Purple);
  targetVisual.Brush.StartAnimation("Color", animation);

But can't figure out how to connect this concept to a plain, old foreground brush on a TextBlock.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

等数载,海棠开 2025-01-29 22:37:16

您可以尝试以下代码:

  Storyboard _storyboard = new Storyboard();

        ColorAnimation colorAni = new ColorAnimation();
        colorAni.To = Colors.Red;
        colorAni.Duration = new Duration(TimeSpan.FromSeconds(2)); 

        Storyboard.SetTarget(colorAni, MyBlock);
        Storyboard.SetTargetProperty(colorAni, "(TextBlock.Foreground).(SolidColorBrush.Color)");

        _storyboard.Children.Add(colorAni);

        _storyboard.Begin();

You could try the following code:

  Storyboard _storyboard = new Storyboard();

        ColorAnimation colorAni = new ColorAnimation();
        colorAni.To = Colors.Red;
        colorAni.Duration = new Duration(TimeSpan.FromSeconds(2)); 

        Storyboard.SetTarget(colorAni, MyBlock);
        Storyboard.SetTargetProperty(colorAni, "(TextBlock.Foreground).(SolidColorBrush.Color)");

        _storyboard.Children.Add(colorAni);

        _storyboard.Begin();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文