[英]Updating a TextBlock in WPF across pages
I am using a WPF application using the MUI (Modern User Interface) libraries by FirstFloor.我正在使用 FirstFloor 使用 MUI(现代用户界面)库的 WPF 应用程序。 I would like to have the option to have an update page where the user is allowed to type in a message or what have you and what they type in the
RichTextBox
will then be updated on the Home.xaml TextBlock.Text
.我希望有一个更新页面的选项,允许用户在其中输入消息或您拥有的内容以及他们在
RichTextBox
将在 Home.xaml TextBlock.Text
上更新。 I have no idea how to start this.我不知道如何开始。 Can anyone help out?
任何人都可以帮忙吗?
As stated, the question is fairly broad.如上所述,这个问题相当广泛。 It would be better if you would provide a good, minimal , complete code example that shows clearly what you've tried so far, along with a detailed explanation of what that code does and how it's different from what you want.
如果您能提供一个良好的、最小的、完整的代码示例,清楚地显示您到目前为止所尝试的内容,并详细说明该代码的作用以及它与您想要的有何不同,那就更好了。
Barring that…除非……
The most obvious answer seems to me to be: store the text in a string
property somewhere, which is bound to both the RichTextBox
(eg to the Document
property via converter) and the TextBlock.Text
property.在我看来,最明显的答案是:将文本存储在某个
string
属性中,该属性绑定到RichTextBox
(例如,通过转换器绑定到Document
属性)和TextBlock.Text
属性。
Assuming the text should be updated only via the RichTextBox
, you can bind using OneWayToSource
, and likewise to the TextBlock.Text
property as OneWay
.假设文本应仅通过
RichTextBox
更新,您可以使用OneWayToSource
进行绑定,同样可以将TextBlock.Text
属性作为OneWay
进行绑定。 Ie set up the bindings so that they properly reflect the intended flow of information.即设置绑定,以便它们正确反映预期的信息流。 Make sure to select the appropriate
UpdateSourceTrigger
value for your scenario (eg LostFocus
or PropertyChanged
) so that the bound property value is updated according to your needs.确保为您的场景选择合适的
UpdateSourceTrigger
值(例如LostFocus
或PropertyChanged
),以便根据您的需要更新绑定的属性值。
In this way, when the user edits the RichTextBox
, the backing property will be updated to reflect the user's input, and then will be automatically mirrored to the TextBox
as desired.这样,当用户编辑
RichTextBox
,backing 属性将更新以反映用户的输入,然后将根据需要自动镜像到TextBox
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.