Monday, July 13, 2015

WPF ProgressBar IsIndeterminate behavior

Today I found that hiding (collapsing) a WPF ProgressBar control with IsIndeterminate set to true does not stop the control from using the CPU. I am using this control in the status bar of a WPF application as a visual hint to the user that some background task is progressing, a sign that the application is busy.

My approach was simply to show or hide the control with the IsIdeterminate property preset  to True in XAML, by binding to the Visibility property. This proved painfully wrong while testing on a colleague's notoriously slow PC - while idling the application was using CPU (way too much).

Interestingly, when you first create the control in collapsed state, the animation is not enabled, only when it is displayed. After that, the animation code seems to be running all the time. My solution was to bind the same boolean property used to show or hide the control to the IsIndeterminate property. This way I managed to get the CPU down to zero while idling, the way I thought it should be.

The funny part is that this control was also being used on a grid to display the loading status of the underlying list of elements. Ouch...

No comments:

Post a Comment