Attached Property Changed Event? [duplicate]

本小妞迷上赌 提交于 2019-11-29 04:29:32

Why don't you use a binding ? That's precisely what they're designed for...

If, for some reason, you can't use a binding, you can add a handler to be notified when the value of the property changes :

var topDescriptor = DependencyPropertyDescriptor.FromProperty(Canvas.TopProperty, typeof(Rectangle));
var leftDescriptor = DependencyPropertyDescriptor.FromProperty(Canvas.LeftProperty, typeof(Rectangle));
topDescriptor.AddValueChanged(rectangle, rectangle_PositionChanged);
leftDescriptor.AddValueChanged(rectangle, rectangle_PositionChanged);

...

private void rectangle_PositionChanged(object sender, EventArgs e)
{
    ...
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!