完全来源于十月的寒流,感谢大佬讲解
依赖属性

由依赖属性提供的属性功能
与字段支持的属性不同,依赖属性扩展了属性的功能。 通常,添加的功能表示或支持以下功能之一:
资源数据绑定样式动画元数据重写属性值继承WPF 设计器集成 public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); CustomTextBox customTextBox = new CustomTextBox(); customTextBox.IsHightLighted = true; customTextBox.SetValue(CustomTextBox.IsHightLightedProperty, true); } } public class CustomTextBox : TextBox { public bool IsHightLighted { get { return (bool)GetValue(IsHightLightedProperty); } set { SetValue(IsHightLightedProperty, value); } } public static readonly DependencyProperty IsHightLightedProperty = DependencyProperty.Register("IsHightLighted", typeof(bool), typeof(CustomTextBox), new PropertyMetadata(false)); } #region HasText public bool HasText => (bool)GetValue(HasTextProperty); public static readonly DependencyProperty HasTextProperty; public static readonly DependencyPropertyKey HasTextPropertyKey; static CustomTextBox() { HasTextPropertyKey = DependencyProperty.RegisterReadOnly("HasText", typeof(bool), typeof(CustomTextBox), new PropertyMetadata(false) ); HasTextProperty = HasTextPropertyKey.DependencyProperty; } #endregion
附加属性

true1