There is a project:
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()); } } After clicking on the "createReport" button, some calculations occur and the progress bar "should" increase by 10 points as calculations do, but this does not happen. The function starts up in blocking mode. After its execution, the full filled ProgressBar is already visible. How to fix it?
Task.Run, at the same time it will be possible to use async / await, if that. --- To block the interface, you can either switch to theEnabled="false"state all controls you are interested in, or put a semitransparent panel in the UI on top of the entire window. - VladD