在子类中仅更改DependencyProperty元数据的单个选项,可以通过以下步骤实现:
public class MyControl : BaseControl
{
public static readonly DependencyProperty MyPropertyProperty =
DependencyProperty.Register("MyProperty", typeof(string), typeof(MyControl),
new PropertyMetadata("DefaultValue", new PropertyChangedCallback(OnMyPropertyChanged)));
}
public class MyControl : BaseControl
{
public static readonly DependencyProperty MyPropertyProperty =
DependencyProperty.Register("MyProperty", typeof(string), typeof(MyControl),
new PropertyMetadata("DefaultValue", new PropertyChangedCallback(OnMyPropertyChanged)));
public new string MyProperty
{
get { return (string)GetValue(MyPropertyProperty); }
set { SetValue(MyPropertyProperty, value); }
}
}
public class MyControl : BaseControl
{
public static readonly DependencyProperty MyPropertyProperty =
DependencyProperty.Register("MyProperty", typeof(string), typeof(MyControl),
new FrameworkPropertyMetadata("DefaultValue", FrameworkPropertyMetadataOptions.Inherits,
new PropertyChangedCallback(OnMyPropertyChanged)));
public new string MyProperty
{
get { return (string)GetValue(MyPropertyProperty); }
set { SetValue(MyPropertyProperty, value); }
}
}
这样,在子类中就可以仅更改基类DependencyProperty元数据的单个选项。
领取专属 10元无门槛券
手把手带您无忧上云