WPF学习系列019: 3.2.1 依赖属性的实现
3.2.1 依赖属性的实现 通过不同的 Register 方法重载,可以传入 metadata (元数据) 说明: 例如: public class Button : ButtonBase { // 依赖属性 public static readonly DependencyProperty IsDefaultProperty; static Button() { // 注册属性 Button.IsDefaultProperty = DependencyProperty.Register( "IsDefault", typeof(bool), typeof(Button), new FrameworkPropertyMetadata( false, new PropertyChangedCallback(Button.OnIsDefaultChanged))); } // .NET属性包装器(可选) public bool IsDefault { get { return (bool)this.GetValue(Button.IsDefaultProperty); } set { this.SetValue(Button.IsDefaultProperty,value); } } // 属性改变的回调(可选) private static void OnIsDefaultChanged( DependencyObject o, DependencyPropertyChangedEventArgs e) { } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |