[英]Context menu paste in textbox not updated binding element value
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: 以下是用于元素绑定的XAML代码:
<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. 使用通用的Silverlight控件,粘贴在TextBox控件中的文本也会自动粘贴到TextBlock控件中。
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. 我认为问题出在您用来粘贴存储在剪贴板中的文本的代码中,因为您正在设置属性SelectedText
,而您的TextBlock的Text
属性绑定到了TextBox的Text
属性。
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}"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.