如果您插入代码段 propdp ,则不会在DepencendyProperty.Register方法的第一个参数中使用 nameof 运算符作为属性名称创造这样的东西:
public string Text
{
get { return (string)GetValue(TextProperty); }
set { SetValue(TextProperty, value); }
}
// Using a DependencyProperty as the backing store for Text. This enables animation, styling, binding, etc...
public static readonly DependencyProperty TextProperty =
DependencyProperty.Register("Text", typeof(string), typeof(MyContentControl), new PropertyMetadata(""));
如果您使用运算符 nameof ,可能会更好,如下例所示:
public string Text
{
get { return (string)GetValue(TextProperty); }
set { SetValue(TextProperty, value); }
}
// Using a DependencyProperty as the backing store for Text. This enables animation, styling, binding, etc...
public static readonly DependencyProperty TextProperty =
DependencyProperty.Register(nameof(Text), typeof(string), typeof(MyContentControl), new PropertyMetadata(""));
答案 0 :(得分:7)
您可以按照以下步骤修改代码段:
打开文件并从
更改宏的定义public static readonly DependencyProperty $property$Property =
DependencyProperty.Register("$property$", typeof($type$), typeof($ownerclass$), new PropertyMetadata($defaultvalue$));
到
public static readonly DependencyProperty $property$Property =
DependencyProperty.Register(nameof($property$) , typeof($type$), typeof($ownerclass$), new PropertyMetadata($defaultvalue$));
并保存(记得以管理员身份打开文本编辑器。)
重新启动Visual Studio。