I'm binding a text box to a textblock, but it is not updated when I paste something using the context menu.
Following there is the XAML code for element binding:
<uc:CustomTextBox x:Name="txtBoxLastName"
Grid.Row="3"
Grid.Column="1"
Width="80"
Height="25"
HorizontalAlignment="Left" />
<TextBlock Grid.Row="4"
Grid.Column="1"
Width="100"
Height="100"
Text="{Binding Text,
ElementName=txtBoxLastName}" />
Context menu paste code:
this.SelectedText = Clipboard.GetText();
What's wrong with this code? Is there any other way to do the same ?
Regards.
Using the common Silverlight controls, the text pasted in the TextBox control is automatically pasted also in the TextBlock control.
I think the problem is in the code you're using to paste the text stored in the Clipboard, because you're setting the property SelectedText
, when instead your TextBlock's Text
property is bound to the Text
property of the TextBox.
You can change the line from:
this.SelectedText = Clipboard.GetText();
to:
this.Text = Clipboard.GetText();
or, as second option, change the binding in your textblock from this:
Text="{Binding Text, ElementName=txtBoxLastName}"
to this:
Text="{Binding SelectedText, ElementName=txtBoxLastName}"