Note that there are some explanatory texts on larger screens.

plurals
  1. POUpdate Dependency Property prior to program exit
    primarykey
    data
    text
    <p>I have created a dependency property of type Binary on a RichTextBox which allows me to bind to a FlowDocument which is in binary form (byte[]) within the ViewModel. This works well, the property converts to and back correctly.</p> <p>Whenever the RichTextBox looses focus then the value of the dependency property is updated with the new binary representation of the FlowDocument.</p> <p>My problem is that if I have been using the RichTextBox and I close the window, the RichTextBox does not lose focus and hence the dependency property is not updated with the new binary representation of the FlowDocument and therefore new changes are not commited to the database. In my ViewModel I have a method CleanUp which gets called when a ViewModel is getting ready to be disposed, where I can save the updated document.</p> <p>How can I get the dependency property to update itself as the RichTextBox doesn't lose focus if the user clicks to close the window? I brainstormed the following:</p> <ol> <li>Tell the dependency property to update itself via a message broadcast. I am not clear on how to register a message listener within the dependency property.</li> <li>Query the RichTextBox directly, get the Document, convert it to a binary object manually.</li> <li>Get the view to move focus to a dummy control, so that the dependency property now updates itself.</li> </ol> <p>What do you guys think?</p> <p>Update: the on changed event for the dependency property adds a event handler which is waiting for the RichTextBox to loose focus. It is this handler that updates the dependency with its new value. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload