Some dialog views need a connection to operate - if there is no connection, a login dialog should be shown: for example, clicking Create Gist without a connection will first prompt the user to log in.
Achieving this is simple, first make your view model interface implement IConnectionInitializedViewModel
and do any initialization that requires a connection in the InitializeAsync
method in your view model:
public Task InitializeAsync(IConnection connection)
{
// .. at this point, you're guaranteed to have a connection.
}
To show the dialog, call IShowDialogService.ShowWithFirstConnection
instead of Show
:
public async Task ShowExampleDialog()
{
var viewModel = serviceProvider.ExportProvider.GetExportedValue<IExampleDialogViewModel>();
await showDialog.ShowWithFirstConnection(viewModel);
}
ShowFirstConnection
first checks if there are any logged in connections. If there are, the first logged in connection will be passed to InitializeAsync
and the view shown immediately. If there are no logged in connections, the login view will first be shown. Once the user has successfully logged in, the new connection will be passed to InitalizeAsync
and the view shown.