2
votes

I have a WPF application which is built on the MVVM design pattern.

I wish to implement a progress bar in the app, that follows the MVVM pattern.

I found some solutions to implement this using background-worker class. For some reasons i am not allowable to use background worker.

Does any one have any suggestions on how to implement this?

Thanks in advance

2
Implementing Progress bar in an MVVM application is not a big deal, but what you have tried so far, and what issue are u facing to implement? - Vimal CK
Depends very much on Progress of What. - Henk Holterman
Does it means that you're not allowed to use background threads at all or just the background worker? If that's the case your UI will lock up until the whole operation has finished. - XAMlMAX
@VimalCK the problem is not updating progressbar. How can i update in a thread manner. - Subin
@XAMlMAX i am working on an ArcGiS solution which doesn't support bacground-worker. that's my problem. - Subin

2 Answers

2
votes

I would prefer Task over background workers. Anyway, here's a simple implementation of progress bar.

<ProgressBar Value="{Binding ProgressValue}" Maximum="100" Height="20" />

 

public MainViewModel()
{
    Task.Run(() =>
        {
            while (true)
            {
                ProgressValue++;
                Thread.Sleep(250);
            }
        });
    }

    public int ProgressValue
    {
        get { return _progressValue; }
        set { _progressValue = value; OnPropertyChanged(); }
    }
}
1
votes

The basics are very simple.

View:

 <ProgressBar Value="{Binding ProgressValue}" />

ViewModel:

 public double ProgressValue { get/set with INPC }

But the remaining challenge is to set the ViewModels ProgressValue from a non-blocking process in a thread-safe manner.

Your question lacks the details to help with that.