WPF Freeze Control During Update

This is a discussion on WPF Freeze Control During Update within the C# Programming forums, part of the General Programming Boards category; is there a way to tell WPF that I'm going to do a lengthy update on a control (TextBlock), and ...

  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    2,494

    WPF Freeze Control During Update

    is there a way to tell WPF that I'm going to do a lengthy update on a control (TextBlock), and that it shouldn't redraw it until I tell it I'm done? I'm adding a large number of items to the Inlines property, and it has to redraw the entire control every time I add an item, which takes a very long time - about 1 second for every 100 items. I know some other frameworks allow freezing of certain controls, but I haven't been able to find anything in the documentation or on google. I've tried collapsing the TextBlock, and then making it visible again after the update, but it did not improve the performance at all.

  2. #2
    Registered User
    Join Date
    Oct 2006
    Posts
    2,494
    I decided to go a different route. I'm now using a RichTextBox control, and adding my items to a Paragraph object, which I then add to the FlowDocument inside the RichTextBox. RichTextBox handles formatted text much faster than TextBlock, so the operation that was taking 30 seconds now happens in under a second.

  3. #3
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,167
    If you're still interested in an answer, this SO post has some good information: c# - BeginUpdate equivalent in WPF? - Stack Overflow
    If you understand what you're doing, you're not learning anything.

  4. #4
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    Ideally in MVVM you should never touch the controls on the view.

  5. #5
    Registered User
    Join Date
    Oct 2006
    Posts
    2,494
    generally speaking, I'd agree, but it's not always worth the effort to databind everything.

  6. #6
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    Tell that to QA.

  7. #7
    Registered User
    Join Date
    Oct 2006
    Posts
    2,494
    I normally wouldn't revive a post this old, but I actually looked into data binding the RichTextBox, and discovered that it's not a trivial task. it seems to involve subclassing a number of things, and for code that will never run apart from this particular view, it wasn't worth the effort, when I've got many other projects demanding my attention.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. USB Drives cause pc to freeze
    By biosninja in forum Tech Board
    Replies: 5
    Last Post: 06-07-2007, 10:42 PM
  2. Control Window DHCP service by constantly update bandwidth usage!
    By irvineyan in forum Networking/Device Communication
    Replies: 0
    Last Post: 04-07-2007, 10:27 PM
  3. Freeze....
    By Disturbed1 in forum Game Programming
    Replies: 7
    Last Post: 06-05-2003, 05:39 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21