I am using WPF with MVVM. I need some advise on how I can get the progress message to the UI from the following architecture.
UI – File processing window.
ViewModel – Has properties for Message, ProgressValue
The message is bound to the UI textblock to update the ui on what is happening in the background while the user is working on something else.
When the user click Process file, the ViewModel ProcessFile is invoked.
The viewmodel directly does not process any files. It in turn calls a different assembly which does the processing of the file.
Here are the pieces of code (I could not put the actual code here):
XAML:
<StackPanel>
<TextBlock Text="{Binding Message}" />
<ProgressBar MinWidth="250" Height="25" IsIndeterminate="True" />
</StackPanel>
Currently I have it IsIndeterminate. I will change this to show the percentage complete.
ViewModel
private string _message;
public string Message
{
get
{
return _message;
}
set
{
_message=value;
OnPropertyChanged("Message");
}
}
private int _progressValue;
public int ProgressValue
{
get { return _progressValue;}
set
{ _progressValue=value;
OnPropertyChanged("ProgressValue");
}
}
public void StartProcess(string fileName)
{
ThreadStart tStart = delegate()
{
differentAssembly.StartProcess(string fileName);
};
Thread processThread = new Thread(tStart);
processThread.IsBackground = true;
processThread.Start();
}
Now with that said how do I get the progress information from the differentAssembly. This will be a message stating the progress and a percentage.
Thanks for your help.
I had the same question on increasing the progress bar value from different assembly.
Instead of calling thread which of course have good number of advantages I used the Observable pattern. Which uses the delegates and background worker.
If I am right we could use Observable pattern with MVVM.
Let me know if I answered your question.