Работы с ProgressBar в паттерне MVVM
Есть проект:
EGEModel.cs
class EGEModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
private int _currentProgress;
public int currentProgress
{
get { return _currentProgress; }
set
{
if (_currentProgress != value)
{
_currentProgress = value;
OnPropertyChanged("currentProgress");
}
}
}
public void createReport()
{
currentProgress = 0;
... //
currentProgress += 10;
... //
currentProgress += 10;
}
}
MainWindow.xaml
...
<dxb:BarButtonItem x:Name="createReportView" Command="{Binding ClickCommand}" />
...
<dxb:BarEditItem Name="ProgressBar" EditValue="{Binding ege.currentProgress, Mode=TwoWay}" />
Command.cs
public class Command : ICommand
{
public Command(Action<object> action)
{
ExecuteDelegate = action;
}
public Predicate<object> CanExecuteDelegate { get; set; }
public Action<object> ExecuteDelegate { get; set; }
public bool CanExecute(object parameter)
{
if (CanExecuteDelegate != null)
{
return CanExecuteDelegate(parameter);
}
return true;
}
public event EventHandler CanExecuteChanged
{
add { CommandManager.RequerySuggested += value; }
remove { CommandManager.RequerySuggested -= value; }
}
public void Execute(object parameter)
{
if (ExecuteDelegate != null)
{
ExecuteDelegate(parameter);
}
}
}
MainWindowViewModel.cs
class MainWindowViewModel
{
public EGEModel ege { get; set; }
public ICommand ClickCommand { get; set; }
public MainWindowViewModel()
{
ClickCommand = new Command(arg => ege.createReport());
}
}
После нажатия на кнопку "createReport" происходят некие вычисления и прогресс бар "должен" увеличиваться по мере вычислений на 10 пунктов, но этого не происходит. Функция как бы запускается в блокирующем режиме. После ее выполнения уже видно полный заполненный ProgressBar. Как это исправить?
Источник: Stack Overflow на русском