I have a control called BasicUserControl2 which contains only a TextBox. I would like to register a dependency property that exposes the TextBox nested inside the control. This so that in a parent control say BasicUserControl1 I can write something like
<tt:BasicUserControl2 TextBox.FontSize="10" />
I currently have the following dependency property:
public TextBox TextBox
{
get { return (TextBox)_textBox; }
set { this.SetValue(TextBoxProperty, value); }
}
public static readonly DependencyProperty TextBoxProperty = DependencyProperty.Register(
"TextBox", typeof(TextBox), typeof(BasicUserControl2));
What kind of property do I need to register? I am trying to avoid having to map properties on the textbox individually to identical properties on the parent UserControl.
You need to create an Attached property instead of Dependency property on your custom UserControl.