locked
Detecting when a block is added to the RichText control RRS feed

  • Question

  • Is there any efficient way to know when a block has been added to the RichTextBox? In my case, I need to know when a table has been pasted, so that I can clear out any borders in it. I currently subscribe to the TextChanged event, and every time it is fired I loop through all of the existing Document.Blocks to see if there is one I have not seen yet. This seems very ineficient,  as it amounts to checking on every keystroke!

    Any ideas?
    • Edited by ddeutsch Tuesday, December 23, 2008 7:10 PM fixed punctuation
    Tuesday, December 23, 2008 7:09 PM

All replies

  • Hello ddeutsch,

       Here is a way can reduce the checking.

       TextChangedEventHandler delegate accepts a TextChangedEventArgs which has a Changes property.


       If the TextChanged event occurs as a result of a property change, Changes is an empty collection. 

       More in 
    Changes 

       If the Changes return an empty collection, we don't need to loop through the document.

       Thanks.


    Please mark the replies as answers if they help and unmark them if they provide no help
    • Marked as answer by Hua Chen Wednesday, December 31, 2008 4:12 AM
    • Unmarked as answer by ddeutsch Tuesday, January 6, 2009 4:53 PM
    Thursday, December 25, 2008 10:08 AM