如何在WPF处理Canvas.Top更改事件? [英] How do I handle Canvas.Top change event in WPF?

查看:203
本文介绍了如何在WPF处理Canvas.Top更改事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我定位在画布使用附加属性的元素 Canvas.Top 画布。左。然后用动画的元素被移动到不同的组坐标,像这样的:

I have an element positioned on Canvas using attached properties Canvas.Top and Canvas.Left. Then using animations the element is moved to different set of coordinates, like this:

DoubleAnimation left = new DoubleAnimation( oldLeft, newLeft );
DoubleAnimation top = new DoubleAnimation( oldTop, newTop );

element.BeginAnimation( Canvas.LeftProperty, left );
element.BeginAnimation( Canvas.TopProperty, top );



有没有办法接收事件时 Canvas.Top Canvas.Left 被改变?最好不涉及动画。

Is there a way to receive events whenever Canvas.Top or Canvas.Left is changed? Preferably without relation to animation.

推荐答案

人们可以的抓附加属性更改事件使用 DependencyPropertyDescriptor 小号 AddValueChanged 方法:

One can catch attached property changed event using DependencyPropertyDescriptor's AddValueChanged method:

var descriptor 
    = DependencyPropertyDescriptor.FromProperty( 
        Canvas.LeftProperty, typeof( YourControlType ) 
      );
descriptor.AddValueChanged( this, OnCanvasLeftChanged );

这篇关于如何在WPF处理Canvas.Top更改事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆