简体   繁体   中英

Updating a TextBlock in WPF across pages

I am using a WPF application using the MUI (Modern User Interface) libraries by FirstFloor. 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 . 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.

Assuming the text should be updated only via the RichTextBox , you can bind using OneWayToSource , and likewise to the TextBlock.Text property as 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM