【问题标题】:How do I handle Canvas.Top change event in WPF?如何处理 WPF 中的 Canvas.Top 更改事件?
【发布时间】:2011-01-12 15:38:49
【问题描述】:

我使用附加属性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 更改时接收事件?最好与动画无关。

【问题讨论】:

    标签: c# wpf canvas attached-properties


    【解决方案1】:

    可以catch attached property changed event 使用DependencyPropertyDescriptorAddValueChanged 方法:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-12
      • 1970-01-01
      • 1970-01-01
      • 2014-08-27
      • 1970-01-01
      相关资源
      最近更新 更多