WPF或C#的编程过程中,经常需要用到属性或依赖。这时,如果全手动书写这些重复的代码太过于费时,还容易出错。而VS本身是有提供自动生成这类代码的快捷方式的。
如:自动生成属性
输入propa,按两次TAB键,即自动生成属性代码
public int MyProperty { get; set; }
输入propdp,按两次TAB键,即自动生成依赖属性代码
public int MyProperty
{
get { return (int)GetValue(MyPropertyProperty); }
set { SetValue(MyPropertyProperty, value); }
}
// Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc...
public static readonly DependencyProperty MyPropertyProperty =
DependencyProperty.Register("MyProperty", typeof(int), typeof(ownerclass), new PropertyMetadata(0));