12

我有一个元素定位在Canvas使用附加属性Canvas.TopCanvas.Left. 然后使用动画将元素移动到不同的坐标集,如下所示:

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

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

有没有办法在任何时候Canvas.TopCanvas.Left更改时接收事件?最好与动画无关。

4

1 回答 1

24

可以使用's方法捕获附加属性更改事件DependencyPropertyDescriptorAddValueChanged

var descriptor 
    = DependencyPropertyDescriptor.FromProperty( 
        Canvas.LeftProperty, typeof( YourControlType ) 
      );
descriptor.AddValueChanged( this, OnCanvasLeftChanged );
于 2010-02-05T14:01:55.180 回答