向数据绑定属性添加逻辑以在 WPF 中启动动画

发布于 2024-09-10 20:31:24 字数 602 浏览 4 评论 0原文

我觉得这是一个非常简单的问题,但我在互联网上找不到任何想要做这样的事情的人的例子。我现在拥有的是我在 WPF 中制作的半圆仪表控件。我有一个 RotateTransform,它的角度绑定了数据,因此当数据进入时,它会直观地显示角度。问题是有些值是 +90 度,而且仪表的外观也很难看到指针超过 80 度点。现在我有一个故事板,有 3 个框架,针在 70 度和 73 度之间“摆动”。

我一直在试图找出某种方法来为所有这些添加逻辑,以便在 +/- 70 度值时动画将循环播放,使仪表呈现出“触底”的外观。我找到了大量有关触发器之类的信息,但我找不到任何想要添加逻辑来生成动画的示例。我觉得我需要某种回调之类的东西。起初我认为数据转换器是理想的选择,但随着我对这些选项的研究越多,我认为它们行不通。

编辑: 我正在寻找类似的东西...

if (angle > 70)
    object.BeginAnimation(WobbleRight)
else if (angle < -70)
    object.BeginAnimation(WobbleLeft)
else
    object.Angle = angle

但是每次角度更新时都需要检查这一点。这只是回调的工作吗?

I feel like this is a very simple question, but I can't really find any examples on the internet of anyone who wants to do something like this. What I have right now is a half circle gauge control that I made in WPF. I have a RotateTransform that has data bound to its angle so as the data comes in it shows the angle visually. The problem is some of the values are +90 degrees and the way the gauge looks as well it gets harder to see the needle past about the 80 degree point. Right now I have a storyboard that has 3 frames with the needle "wobbling" between like 70 and 73 degrees.

What I have been trying to figure out is some way to add logic to all of this so that at values of +/- 70 degree values the animation will loop giving the gauge a "bottoming out" look to it. Ive found plenty of info on triggers and whatnot but I can't find any examples of people wanting to add logic to produce animations. I feel like I need some sort of callback or something. At first I was thinking a data converter would be the ideal choice but the more I look into these options I think they won't work.

EDIT:
I'm lookin for something like...

if (angle > 70)
    object.BeginAnimation(WobbleRight)
else if (angle < -70)
    object.BeginAnimation(WobbleLeft)
else
    object.Angle = angle

However it would need to check this every time Angle gets updated. Would this just be the job for a callback?

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

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

发布评论

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

评论(1

南…巷孤猫 2024-09-17 20:31:24

没关系,我在某种程度上弄清楚了如何做到这一点。刚刚创建了一个自定义依赖属性并为其提供了回调。从那里您可以在每次值更新时执行一些操作。这就是我认为需要的。

Nevermind I figured out how to do it to a degree. Just created a custom dependency property and had a callback for it. From there you can do stuff every time the value updates. This is sorta what I was thinking was needed.

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