更新时间:2022-04-12 18:30:28
在XAML中(或通过绑定或动画等)设置依赖项属性时,WPF无需调用CLR包装器即可直接访问基础DependencyObject和DependencyProperty.请参见 XAML加载和依赖项属性, 自定义依赖项属性的含义.
When a dependency property is set in XAML (or by binding or animation etc.), WPF directly accesses the underlying DependencyObject and DependencyProperty without calling the CLR wrapper. See XAML Loading and Dependency Properties, Implications for Custom Dependency Properties.
In order to get notified about changes of the Number
property, you have to register a PropertyChangedCallback:
public static readonly DependencyProperty NumberProperty =
DependencyProperty.Register("Number",
typeof(double),
typeof(FormattedTextBox),
new FrameworkPropertyMetadata(NumberPropertyChanged));
private static void NumberPropertyChanged(
DependencyObject obj, DependencyPropertyChangedEventArgs e)
{
var textBox = obj as FormattedTextBox;
...
}