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

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

问题描述

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

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 方法:

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

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

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