引用大佬写的文章记录一下方便收藏学习,写得非常好
WPF依赖属性详解 - 痕迹g - 博客园 (cnblogs.com)
依赖属性
快捷键方式 输入propdp 按两下TAB键
//依赖属性快捷键方式 propdp
public Thickness PlaceholderPadding
{
get { return (Thickness)GetValue(PlaceholderPaddingProperty); }
set { SetValue(PlaceholderPaddingProperty, value); }
}
// Using a DependencyProperty as the backing store for placeholderPadding. This enables animation, styling, binding, etc...
public static readonly DependencyProperty PlaceholderPaddingProperty =
DependencyProperty.Register("PlaceholderPadding", typeof(Thickness), typeof(UTextBox), new PropertyMetadata(new Thickness(0, 0, 0, 0)));
附加属性
快捷方式 输入propa 按两下TAB键
//附加属性快捷方式 propa 按两下TAB键
public static ICommand GetClearCommandProperty(UIElement obj)
{
return (ICommand)obj.GetValue(ClearCommandProperty);
}
public static void SetClearCommandProperty(UIElement obj, ICommand value)
{
obj.SetValue(ClearCommandProperty, value);
}
public static readonly DependencyProperty ClearCommandProperty =
DependencyProperty.RegisterAttached("ClearCommand", typeof(ICommand), typeof(UTextBox), new FrameworkPropertyMetadata(new DelegateCommand<UTextBox>(OnClearCommandExecute)));
自定义的TextBox控件用了上面的依赖属性和附加属性