I have a custom MyControl : UserControl with dependency property
string Text
Inside the MyControl in XAML I have a TextBox.
I wish to bind the Text dependency property of MyControl to the Text dependency property of the TextBox.
What is the best way to do this? Can I declare the dependency property of MyControl to pass through to the child depenendency property?
The easiest way is to assign a x:Name="root"
attribute to the root of your MyControl.xaml
file, and then use a binding like this for your TextBox
:
<TextBox Text="{Binding Text, ElementName=root}" />
(You can specify your own name for root
.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With