C# 为什么“;propdp&x201D;代码段没有';t在';是否重新声明依赖项属性?
当您使用propdp代码片段创建依赖项属性时,它不会为您提供创建依赖项属性的类的正确名称,您必须手动键入它,如下一个示例所示:C# 为什么“;propdp&x201D;代码段没有';t在';是否重新声明依赖项属性?,c#,visual-studio,visual-studio-2015,code-snippets,C#,Visual Studio,Visual Studio 2015,Code Snippets,当您使用propdp代码片段创建依赖项属性时,它不会为您提供创建依赖项属性的类的正确名称,您必须手动键入它,如下一个示例所示: namespace YourApp.Controls { public sealed class YourButton : Control { public YourButton() { this.DefaultStyleKey = typeof(YourButton); }
namespace YourApp.Controls
{
public sealed class YourButton : Control
{
public YourButton()
{
this.DefaultStyleKey = typeof(YourButton);
}
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(ownerclass), new PropertyMetadata(0));
}
}
我不希望将您的按钮作为默认值所有者类,在这种情况下,我希望您的按钮
如何修改代码段以提出正确的名称?分析ctor代码段的源代码很容易知道问题:您只需添加下一行:
<Function>ClassName()</Function>
使用中建议的修改使其使用name of运算符。分析ctor代码片段的源代码很容易知道问题:只需添加下一行:
<Function>ClassName()</Function>
使用中建议的修改使其使用操作员的名称。我认为没有必要重新启动VS,请尝试此操作。你必须重新启动VS。我认为没有必要重新启动VS,请试试这个。你必须重新启动VS。
namespace YourApp.Controls
{
public sealed class YourButton : Control
{
public YourButton()
{
this.DefaultStyleKey = typeof(YourButton);
}
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(YourButton), new PropertyMetadata(0));
}
}