c# - 如何处理 WPF 中的 Canvas.Top 更改事件?

标签 c# wpf canvas attached-properties

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

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 发生变化时接收事件?最好与动画无关。

最佳答案

一 jar catch attached property changed event使用 DependencyPropertyDescriptorAddValueChanged 方法:

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

关于c# - 如何处理 WPF 中的 Canvas.Top 更改事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2192612/

相关文章:

wpf - 使用Entity Framework 4创建Blob属性吗?

wpf - 通过隐藏代码更新 WPF DataGrid 列标题文本

jquery - 我的 HTML5 Canvas 代码可以转换为 SVG 吗?

html - 用 Canvas 缩小大图像。平滑

html - threejs Canvas todataurl 是空白的

c# - 检查列表中是否存在具有特定值的对象

c# - 微软编码标准文档

c# - WPF UI 渲染问题

c# - 如何检查系统日期格式是否与存储在mysql中的不同

c# - 当我尝试添加图像时,MVC 总是返回 null