本文介绍了如何在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更改事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!