0

Suppose I have usercontrol with textbox:

<UserControl x:Class="WpfApp5.UserControl1"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             ...
             d:DesignHeight="450" d:DesignWidth="800">
    <Grid>
        <TextBox Name="MyTextBox" Height="30"/>
    </Grid>
</UserControl>

From the mainwindow I want to bind this TextBox to diffrerent properties, I need something like:

<Window x:Class="WpfApp5.MainWindow"
        ...
        Title="MainWindow" Height="200" Width="200">
    <Grid DataContext="{Binding Source={StaticResource Locator}, Path=MyViewModel}">
        <UserControl MyTextBox.Text="{Binding Prop1}"/>
        <UserControl MyTextBox.Text="{Binding Prop2}"/>
        <UserControl MyTextBox.Text="{Binding Prop3}"/><!---->
    </Grid>
</Window>

how to achive that?

Codey
  • 487
  • 1
  • 8
  • 27
  • But how do I bind to multiple properties? that's not appears in the given ""duplicated"" answer!! – Codey Aug 15 '19 at 05:36
  • You mean *different* properties. Just as you have it now, except that there is a valid property name instead of `MyTextBox.Text`. – Clemens Aug 15 '19 at 05:55
  • @Clemens I mean, let's say I want to bind to each instance of `` a differente string from the mainwindow viewmodel – Codey Aug 15 '19 at 05:59
  • Exactly what I just said. Think about it for a moment. In case it isn't totally obvious, you would bind a UserControl's dependency property like `` – Clemens Aug 15 '19 at 05:59

0 Answers0