Reputation: 12876
In a WPF application I have defined a progress bar.
<ProgressBar Minimum="0" Maximum="{Binding TotalItemCount}" Value="{Binding CurrentItemCount, UpdateSourceTrigger=PropertyChanged}" />
However I have the problem that the progress bar is completely filled, i.e. 100 % directly after having started the application although I initially set the properties to the following values:
TotalItemCount = 0;
CurrentItemCount = 0;
As soon as I change TotalItemCount
to 1
the progress bar is correctly set to 0 %. It seems to me that the control interpretes 0 from 0 being 100 % .
How can I correct initialze the progress bar to 0 %?
Upvotes: 2
Views: 1909
Reputation: 12876
I did what some fellows propsed: the progress bar is hidden as long as the counter is 0.
Upvotes: 1
Reputation: 1735
You can write a converter for ProgressBar maximum value like this:
[ValueConversion(typeof(double), typeof(double))]
public class ProgressBarMaximumConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if ((double)value == 0)
{
return 1;
}
return value;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return null;
}
}
Upvotes: 1
Reputation: 317
public int MaxCountForProgress
{
get
{
if (TotalItemCount == 0)
return int.MaxValue;
return TotalItemCount;
}
}
...
ProgressBar Minimum="0" Maximum="{Binding MaxCountForProgress}" Value="{Binding CurrentItemCount, UpdateSourceTrigger=PropertyChanged}"
Upvotes: 4