I am using C# WPF MVVM.
The ProgressBar is colored red after a while, but it does not show any movement, and the percentage is not incremented and stays at 0%.
I appreciate your help!
The ProgressBar is colored red after a while, but it does not show any movement, and the percentage is not incremented and stays at 0%.
XAML:
<Button Grid.Row="0" Content="Start" Command="{Binding StartCommand}" Style="{StaticResource RotatingButton}"
FontWeight="Bold" HorizontalAlignment="Left" Width="60" Height="24" Margin="10,10,0,15" />
<ProgressBar Grid.Row="1" Name="pbProgress" Minimum="0" Maximum="{Binding PropMaxValue}" Value="{Binding PropCurrentValue}"
Height="25" Background="Black" Foreground="Red" Margin="20,20,22.4,0" />
<TextBlock Grid.Row="1" Text="{Binding PropCurrentValuePercent, StringFormat={}{0:0}%}"
HorizontalAlignment="Center" VerticalAlignment="Bottom" Foreground="White" FontWeight="Bold" Margin="5" />
ViewModel:
class MainWindowViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
//private double maxValue = 1000000;
private double maxValue = 50;
public double PropMaxValue
{
get
{
return maxValue;
}
set
{
maxValue = value;
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs("PropMaxValue"));
}
}
}
private double propCurrentValue;
public double PropCurrentValue
{
get { return propCurrentValue; }
set
{
propCurrentValue = value;
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs("PropCurrentValue"));
}
}
}
private double propCurrentValuePercent;
public double PropCurrentValuePercent
{
get
{
//return (int)((PropCurrentValue - 0) / (PropMaxValue - 0) * 100);
return (double)((PropCurrentValue - 0) / (PropMaxValue - 0) * 100);
}
set
{
propCurrentValuePercent = value;
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs("PropCurrentValuePercent"));
}
}
}
private bool canExecute = true;
private ICommand startCommand;
public ICommand StartCommand
{
get
{
if (startCommand == null)
startCommand = new RelayCommand(RunProgressBar, param => this.canExecute);
return startCommand;
}
set
{
startCommand = value;
}
}
private void RunProgressBar(object sender)
{
PropCurrentValue = 0;
for (double i = 0; i <= PropMaxValue; i++)
{
PropCurrentValue++;
}
}
}
Last edited by a moderator: