开发者

Adding logic to a data bound property to initiate animations in WPF

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 ha开发者_开发百科ve 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜