Is there a suspend/resume layout feature?

GaetanFGaetanF USMember ✭✭✭

Hi folks,

Is there currently any built-in support for batch processing when dealing with UI controls?
For example, a ListView is bound to an ObservableCollection and multiple Add/Insert/Remove happen contiguously. Is there a way to suspend the invalidation/layout cycle to avoid wasting CPU time and hogging the UI thread?

Cheers

Best Answers

Answers

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    The UI gets a notification for sleep and resume.
    I listen for that then raise a MessageCenter message. Any subscribing class that has to care about such things can then react.

  • GaetanFGaetanF USMember ✭✭✭

    Thanks @ClintStLaurent for your quick answer.
    Could you be a bit more specific, I am not sure to understand? Through which mechanism do you subscribe to these events? How do you intercept them?

  • JohnHardmanJohnHardman GBUniversity mod
    edited February 2018

    @GiampaoloGabba - Ah yes, I'd forgotten about those MVVM helpers. Those should do the job nicely :-)

    However, the build status is currently showing as failing. In that circumstance, I'd feel more comfortable copying the source of the bits I use into my own project, rather than relying on the NuGet, but that's just me.

  • GaetanFGaetanF USMember ✭✭✭

    Thanks guys for your helpful answers.
    It helped me to realise that what I wanted to do was a MVVM anti pattern so I think I should go back to the basis and redesign my solution properly.

    Cheers

  • SteveShaw.5557SteveShaw.5557 USMember ✭✭✭

    @GaetanF - why do you conclude that it is "an MVVM anti-pattern"?

    Its a well-defined change in the model, that we wish UI to respond to; ObservableRangeCollection is merely a way to improve the performance of adding a number of items at one time.

    Likewise, for any other changes you might make.
    This is a common need.
    I see no problem with using https://github.com/jamesmontemagno/mvvm-helpers/blob/master/MvvmHelpers/ObservableRangeCollection.cs or similar.

    IMHO, it would only be an anti-pattern if UI details leaked into the ObservableRangeCollection.

    Notice that link includes a method

    ReplaceRange(IEnumerable<T> collection)
    

    This can be used to build ANY new contents, combining existing and new items as desired.
    Build such a list, then call ReplaceRange, to replace all contents in one step.
    Effectively setting the source to a new collection, but preserving the identity of the original (which is useful sometimes).

Sign In or Register to comment.