views:

883

answers:

2
<ProgressBar Foreground="Red"
             Background="Transparent"
             Value="{Binding NumFailed, Mode=OneWay}"
             Minimum="0"
             Maximum="{Binding NumTubes, Mode=OneWay, Converter={x:Static wpftools:DebuggingConverter.Instance}, ConverterParameter=Failedprogressbar}"
             FlowDirection="RightToLeft"
             Style="{DynamicResource {x:Static wpftools:CustomResources.StyleProgressBarVistaKey}}" />

This is what my progressbar looks like at the moment. The style came from http://mattserbinski.com/blog/look-and-feel-progressbar and the DebuggingConverter is a no-op converter that prints the value, type and parameter to the Console. I have verified that the converter for the Maximum is being called when my NumTubes property is changed.

Basically, the ProgressBar won't redraw until the Value changes. So, if I have 2 tubes and 1 is failed, even if I add 20 more tubes, the bar is still half filled until the NumFailed changes, then the proportion is updated. I've tried adding spurious notifications of the NumFailed property, but that apparently doesn't work since the value didn't change.

Ideas?

+2  A: 

It looks like the bar size is calculated in the private method ProgressBar.SetProgressBarIndicatorLength. It's only called from OnValueChanged, OnTrackSizeChanged, and OnIsIndeterminateChanged.

You could call SetProgressBarIndicatorLength through reflection, or cycle one of the properties that causes it to be called. This is lame, but it doesn't look like the ProgressBar was designed so that the Maximum and Minimum would be changed in mid-progress.

Regardless of which method you choose, you can figure out when the Maximum property changes by using DependencyPropertyDescriptor.AddValueChanged:

DependencyPropertyDescriptor dpd = DependencyPropertyDescriptor.FromProperty(ProgressBar.MaximumProperty, typeof(ProgressBar)));
if (dpd != null)
{
   dpd.AddValueChanged(myProgressBar, delegate
   {
      // handle Maximum changes here
   });
}
Robert Macnee
Could I do a simple subclass to trigger this do you think?
Tom
Actually, you don't need to subclass, you can get a DependencyPropertyDescriptor for the MaximumProperty and call AddValueChanged. I'll add this to my post.
Robert Macnee
Thanks, I toggled IsIndeterminate true/false inside the delegate. Working great.
Tom
A: 

Hi

I have posted an article in CodeProject at http://www.codeproject.com/KB/WPF/WPFWaitProgressBar.aspx - can you please check out and let me know if that helps in your scenario. Thanks

Raja

Raja Lakshman
This article is still being written and is not currently available for general viewing
Tom