首页 新闻 会员 周边

关联属性,又称:依赖属性

0
悬赏园豆:15 [已关闭问题] 关闭于 2011-12-03 18:30

这是“深蓝色右手”里写的呢。

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);
        }

“关联属性,又称:依赖属性 ”究竟是怎么回事???   

能解释下这三个方法是怎样定义属性的吗???

[CC]的主页 [CC] | 初学一级 | 园豆:61
提问于:2011-11-04 21:06
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册