lundi 29 juin 2015

How to determine whether two FlowDocuments have the same content?

I'm creating a small text editor using a RichTextBox in WPF. When the editor is closed I'd like to ask the user if he really wants to close, but ONLY IF there are unsaved changes. I made a copy of the RTB's original FlowDocument and want to compare it in the RTB.SelectionChanged event with the current FlowDocument of the RTB to see if the user has changed the document. If so, a flag is set that tells me there are some unsaved changes. However, I dont't really know how to compare the two FlowDocuments, i.e. how to determine whether their contents are the same or not (including formatting such as fontsize, -weight, textdecorations...). I tried .Equals but that doesn't seem to work at all. I'm aware of how to get the plain text aut of a RTB and compare that but it's important to me to also check whether the formatting of the text has changed or not.

I'd really appreciate your help! Thanks!

Aucun commentaire:

Enregistrer un commentaire