Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF ProgressBar doesn't update?

I am trying to update my progressbar by using data bindings. The XAML file contains the progressbar:

<ProgressBar Height="23" Name="progressBar" VerticalAlignment="Bottom" Margin="207,444,0,0" Minimum="0" Maximum="{Binding ProgressBarMax}" Value="{Binding ProgressBarValue}" />

My relevant C# class contains the getter & setter:

    private int progressBarMax;
    public int ProgressBarMax
    {
        get 
        {
            if (this.progressBarMax == 0)
                this.progressBarMax = 1;
            return this.progressBarMax; 
        }
        set 
        {
            this.progressBarMax = value; 
        }
    }

    private int progressBarValue;
    public int ProgressBarValue
    {
        get 
        { 
            return progressBarValue; 
        }
        set 
        { 
            progressBarValue = value; 
        }
    }

In my "update" method the maximum is being set. For example like this.progressBarMax = 100;. In a loop the progressbar value is getting the value += 1. To see the updates I used Application.DoEvents(), later I will implement threads. The data binding has to be correct, because I have other components that work fine.

So why doesn't my progressbar update?

Thank you for your help.

like image 681
oopbase Avatar asked Sep 10 '26 07:09

oopbase


1 Answers

You need to implement a way to let your ProgressBar be notified whenever ProgressBarValue changes. Have a look at the INotifyPropertyChanged interface.

like image 192
Jens Avatar answered Sep 12 '26 05:09

Jens



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!