这是“深蓝色右手”里写的呢。
public Point Coordinate {
get { return (Point)GetValue(CoordinateProperty); }
set { SetValue(CoordinateProperty, value); }
}
public static readonly DependencyProperty CoordinateProperty = DependencyProperty.Register(
"Coordinate",
typeof(Point),
typeof(Sprite),
new PropertyMetadata(ChangeCoordinateProperty)
);
static void ChangeCoordinateProperty(DependencyObject d, DependencyPropertyChangedEventArgs e) {
Sprite sprite = (Sprite)d;
Point p = (Point)e.NewValue;
Canvas.SetLeft(sprite, p.X - sprite.Center.X);
Canvas.SetTop(sprite, p.Y - sprite.Center.Y);
Canvas.SetZIndex(sprite, (int)p.Y);
}
“关联属性,又称:依赖属性 ”究竟是怎么回事???
能解释下这三个方法是怎样定义属性的吗???