I use IDialogCoordinator on ViewModel and everything works fine.
But if in viewmodel i have instance of other class, it doesn't work. I try to pass dialogCoordinator in constructor, but I've got a message "Context is not registered".
How to achieve that?
Viewmodel:
public viewModel
{
private IDialogCoordinator dialogCoordinator;
public ICommand SyncCommand { get { return new RelayCommand(SyncCommand_ExecutedAsync); } }
public viewModel(IDialogCoordinator _coordinator)
{
coordinator = _coordinator;
}
private void SyncCommand_ExecutedAsync()
{
var sync = new IndexUpdater(dialogCoordinator);
var b = sync.Start().Result;
}
}
IndexUpdater:
public IndexUpdater(IDialogCoordinator _dialogCoordinator)
{
dialogCoordinator = _dialogCoordinator;
}
public async Task<bool> Start(bool reset = false)
{
var output = true;
ProgressDialogController controller = await dialogCoordinator.ShowProgressAsync(this, "HEADER", "MESSAGE", true, new MetroDialogSettings { NegativeButtonText = "Close" });
controller.Minimum = 0;
controller.Maximum = 100;
for (int x = 0; x < 100; x++)
{
if (controller.IsCanceled)
{
output = false;
break;
}
Thread.Sleep(200);
controller.SetProgress(x + 1);
controller.SetMessage("x = " + x);
}
await controller.CloseAsync();
return output;
}
In this case I got Exception: "InvalidOperationException: Context is not registered. Consider using DialogParticipation.Register in XAML to bind in the DataContext."
If I put ProgressDialogController directly in viewModel.SyncCommand_ExecutedAsync() method, then it works.
How to Register IndexUpdater class or how to pass dialogCoordinator there?
Thanks in Advance