WPF: How to update UI without blocking animations - wpf

in my WPF application I have a ListView with a GridView as it's View. The ItemsSource of the ListView is bound to an ItemsCollection in the ViewModel.
This GridView has a lot of columns and the ListView can have a lot of items.
When the windows is loading or the user updates this ListView I show a loading animation while retrieving the new data from the server and updating the ItemsCollection in the ViewModel with the new data.
This retrieving of data is already done asynchronously, so the loading animation keeps spinning. But as soon as the data is retrieved and the binding is to update the ListView, the loading animation freezes until the update of the UI is finished.
How can I make my loading animation keep spinning even when the binding updates the UI?
Thank you for your help.

EDIT:
Well, that binding runs in the main thread, the same thread your animation runs.
Clearly my previous solution wont help you. You will have to find a way to reduce the time it takes to rendering view. Share some working code, maybe someone can help you.
Other alternative is to stop the animation and show something static. That way you hide the problem. Its not a great solution, but if you don't find other, this could your only one.

Related

WPF loading panel and UI freeze

I have a mainwindow which displays a 'Please wait' panel containing a loading gif whenever I do some work in a Task. The gif plays fine when the data is being compiled, but when the INPC logic to refresh the UI controls is being executed (thus on the main UI thread), the app freezes for a split second and my gif does not play smoothly anymore.
For instance, I am following the MVVM pattern, I have a datagrid in my view which is binded to an ObservableCollection MyBindedCollection. In the constructor of my viewmodel which runs in a Task, I create a tmp observable collection and when the process is finished, I set the variable MyBindedCollection to tmp (thus not adding one by one my items to it). The INPC logic is of course in the setter of my property MyBindedCollection.
Is there anyway to prevent this? any idea would be appreciated.
#ZoolWay yes, no way around that I'm affraid. I'll just fade out my wait panel and thread.Wait enough time for the animation to finish before displaying my content. Thus it'll appear smooth. Thanks for your time.

WPF ListBox item load step-by-step animation

I want to create user control based on ListBox (ListView) with such animation: the items in listbox do not loads all at once, they have to load step-by-step (item-by-item, first then second, then third, etc.) with some timeout between them.
How can I do that?
Thanks in advance for your help :)
The suggested Slide Animation is a view animation. I think you want a data animation. Bind to an alternate view only collection. Populate this collection one at a time from the backing collection with the aid of a timer. A quick search reveals that a Dispatch Timer seems to be preferred with WPF usage.

Silverlight Preload Controls

Is there a way to get Silverlight databound controls to load in the background to shorten load times during another part of application use? Specifically, I have a tab control containing a datagrid that is slow to load when there are large number of columns and rows. The performance hit occurs the first time I click the tab. Is there a way to force this load on a background thread when app first opens or something similar?
Not sure this is exactly relevant but I just resolved an issue I had where I was firing up a new grid (which was already loaded but not visible). In the process of making it visible I also assign the ItemSource of a datagrid inside which - via a converter - generates controls. What I found was that although the datagrid in silverlight typically only loads rows it needs to (based on visibility) in my case the code sequence to show the grid and bind was happening too quickly and because the grid wasn't yet shown it (silverlight) decided it needed to load all the rows.
Calling UpdateLayout() prior to generating the controls and binding resolved the issue.

Show Loading Image when TreeView Node is clicked in WPF

The question is we have a WPF application, which has Tree View. On the click of node Report gets generated which has no time interval (I mean no clue how much time it will take). So I am planning to show a Loading.gif file on the window till the report is generated.
How can I make the image (.gif) visible while the main window process to show the report and after showing the report I need to hide the image.
Do you have any other alternate method to do so.
Appreciate your help in advance.
You can make use of Extended WPF Toolkit's BusyIndicator.
Here's a sample of how to make async multi-threaded treeview -> http://www.codeproject.com/KB/WPF/ThreadedWPFExplorer.aspx
The general technique for this is:
1) Create an IsBusy property in the view model for your window; make sure it raises PropertyChanged when it changes.
2) In the code executed when the item is clicked, use a BackgroundWorker to run the long-running task.
3) Before calling BackgroundWorker.DoWork(), set IsBusy to true. In the event handler called when the BackgroundWorker.RunWorkerCompleted is raised, set IsBusy to false.
4) In the DataTemplate for the window, add a Style with a DataTrigger bound to IsBusy, and use that to control the visibility of the image.
Note that you may be able to move IsBusy (and the long-running task and the BackgroundWorker) to the item view model instead of the window view model, and add a "Loading" animation to the DataTemplate for the item.
If you do this, the user can start multiple items loading simultaneously, and the entire application doesn't lock up just because one item in the TreeView got clicked on. (Of course, you have to deal with any multithreading issues involved in generating multiple reports simultaneously).

WPF Performance Degradation During UI Render

I have the following components in a WPF application:
(1) Window
(2) ContentPresenter in the Window that is bound to a property in the underlying ViewModel. This Property references another ViewModel.
(3) A DataTemplate for the ViewModel that will be bound to the ContentPresenter referenced above. This data template instantiates a third-party grid that displays some data.
Whenever the ContentPresenter renders the data from the DataTemplate, it takes approximately three to four seconds for the UI to render. This causes the UI to hang for the duration of the time that it takes to render the content. Since I have little to no control over how the third-party control renders itself - my question involves whether or not it is possible to render content in a way that the UI will not hang.
Please advise.
Thanks.
Chris
How many rows is the grid displaying? And how many of those rows are visible on screen?
I'm asking because it's possible that you've got a UI layout that defeats virtualization. Usually, controls that show a scrollable list of data will perform virtualization. (The built-in ListBox does this, and any 3rd party grid of tolerable quality should do the same.) This is critical for performance, because it means your UI only needs to instantiate those items that are actually visible, rather than everything in your list.
But it's relatively easy to defeat this virtualization by accident. One way is to wrap the list or grid control in a ScrollViewer. You need virtualizing controls to be able to manage their own scrolling for virtualization to work, so the scrolling needs to happen on the inside. Wrapping a control in a ScrollViewer prevents it from doing its own scrolling. Another way it can go wrong is if you plug in a different ItemsPanel. A third possibility is that your list/grid control actually needs to be told to use virtualization.
But if you're using a control that simply takes a long time to render just the stuff you need to show on screen, then there's not much you can do - you'd need to contact the control vendor, or consider using a different vendor...

Resources