Mapping child control dependency properties for binding in WPF

I have a very simple UserControlone called CustomTextBoxwith this XAML:

<UserControl x:Class="CustomTextBox" ... >
    <Grid>
        <TextBox x:Name="InnerTextBox"/>
    </Grid>
</UserControl>

Now when I use CustomTextBoxand want to bind to InnerTextBox.Text, it does not work:

... {Binding ElementName=CustomTextBox, Path=InnerTextBox.Text}

I tried it differently, it doesn't work:

... {Binding ElementName=CustomTextBox.InnerTextBox, Path=Text}

I know that I can define a new dependency property called CustomTextBox.Textand then bind it to InnerTextBox.Text, but I plan to have custom controls with many properties, and it’s damn hard to copy all of them just to support the binding. In addition, copy / wrapping properties mean that each value is stored twice.

WinForms , . WPF XAML .

UserControl?

+4
3

1. DP, , Text
2. xaml :

<TextBox x:Name="InnerTextBox" Text={Binding Text}/> 


3. , DataContext - UserControl

+3

, .

0

All Articles