1

When a wpf custom control is added to the toolbox and dragged onto the MainWindow, the automatically generated text in the XAML editor contains some properties=values by default.

How can I alter this text so that automatically includes some new properties of my custom control and/or remove others?

jmattheis
  • 10,494
  • 11
  • 46
  • 58
  • you misunderstand: When a wpf control is dragged onto the Window from toolbox, the automatically generated text in the XAML editor contains some properties=values *which are not equal to defaults*. What is the point to repeat defaults?? – ASh Aug 02 '17 at 07:04

1 Answers1

0

You can get pretty flexible design time behavior with a combination of System.ComponentModel attributes and DependencyProperty metadata. The PropertyMetadata class has a constructor that takes a default value:

[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

enter image description here

Jason Boyd
  • 6,839
  • 4
  • 29
  • 47