-.
this.MLTBLabel.DataContext = this;
this.MLTBTextBox.DataContext = this;
Noooooooooooooooo!
. -. -. DataContext . , . , .
:
UserControl a x:Name.
<UserControl ...
x:Name="usr">
UserControl , :
<TextBlock Text="{Binding MyDependencyProperty, ElementName=usr}" ... />
UserControl DataContext , :
<TextBlock Text="{Binding MyDataContextProperty}"/>
DataContext UserControl MainWindow, UserControl UserControl. DataContext UserControl , .
, .
:
private void MLTBTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
this.Text = this.MLTBTextBox.Text;
}
private static void LabelTextPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
((MyLabelledTextBox)d).MLTBLabel.Content = (string)e.NewValue;
}
private static void TextPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
((MyLabelledTextBox)d).MLTBTextBox.Text = (string)e.NewValue;
}
. , , .
:
<Label Grid.Row="0" Grid.Column="0" Text="{Binding Text, ElementName=usr}"/>
, , , MainWindow UserControl.
Text="{Binding StringData, Mode=OneWay}"
, DataContext . :
StringData DataContext .
, MainWindow DataContext. ( DataContext UserControl).
, . , .