C# 将自定义控件从工具箱拖放到主窗口时,更改XAML自动生成文本
将wpf自定义控件添加到工具箱并拖动到主窗口时,默认情况下,XAML编辑器中自动生成的文本包含一些properties=值C# 将自定义控件从工具箱拖放到主窗口时,更改XAML自动生成文本,c#,wpf,xaml,custom-controls,toolbox,C#,Wpf,Xaml,Custom Controls,Toolbox,将wpf自定义控件添加到工具箱并拖动到主窗口时,默认情况下,XAML编辑器中自动生成的文本包含一些properties=值 如何更改此文本,以便自动包含自定义控件的一些新属性和/或删除其他属性?通过结合System.ComponentModel属性和dependencProperty元数据,您可以获得非常灵活的设计时行为。PropertyMetadata类有一个采用默认值的构造函数: [Category("MyCustomCategory")] public string MyCustomPro
如何更改此文本,以便自动包含自定义控件的一些新属性和/或删除其他属性?通过结合
System.ComponentModel
属性和dependencProperty
元数据,您可以获得非常灵活的设计时行为。PropertyMetadata
类有一个采用默认值的构造函数:
[Category("MyCustomCategory")]
public string MyCustomProperty
{
get { return GetValue(MyCustomPropertyProperty).ToString(); }
set { SetValue(MyCustomPropertyProperty, value); }
}
public static DependencyProperty MyCustomPropertyProperty =
DependencyProperty
.Register(
"MyCustomProperty",
typeof(string),
typeof(MyCustomUserControl),
new PropertyMetadata("My default value")); // <--- default value
[类别(“MyCustomCategory”)]
公共字符串MyCustomProperty
{
get{return GetValue(MyCustomPropertyProperty).ToString();}
set{SetValue(MyCustomPropertyProperty,value);}
}
公共静态从属属性MyCustomProperty属性属性=
关联属性
.登记(
“MyCustomProperty”,
类型(字符串),
类型(MyCustomUserControl),
新属性元数据(“我的默认值”);// 通过组合System.ComponentModel
属性和dependencProperty
元数据,您可以获得非常灵活的设计时行为。PropertyMetadata
类有一个采用默认值的构造函数:
[Category("MyCustomCategory")]
public string MyCustomProperty
{
get { return GetValue(MyCustomPropertyProperty).ToString(); }
set { SetValue(MyCustomPropertyProperty, value); }
}
public static DependencyProperty MyCustomPropertyProperty =
DependencyProperty
.Register(
"MyCustomProperty",
typeof(string),
typeof(MyCustomUserControl),
new PropertyMetadata("My default value")); // <--- default value
[类别(“MyCustomCategory”)]
公共字符串MyCustomProperty
{
get{return GetValue(MyCustomPropertyProperty).ToString();}
set{SetValue(MyCustomPropertyProperty,value);}
}
公共静态从属属性MyCustomProperty属性属性=
关联属性
.登记(
“MyCustomProperty”,
类型(字符串),
类型(MyCustomUserControl),
新属性元数据(“我的默认值”);//您误解了:当wpf控件从工具箱拖到窗口时,XAML编辑器中自动生成的文本包含一些不等于默认值的属性=值。重复默认值的意义是什么?您误解了:当wpf控件从工具箱拖到窗口上时,XAML编辑器中自动生成的文本包含一些不等于默认值的属性=值。重复默认值有什么意义??