protected override async void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); await StatusBarProvider.TryExecuteAsync(async statusBar => await statusBar.HideAsync()); Guid key = (Guid)e.Parameter; ClientRepository repository = new ClientRepository(); IClient client = repository.FindRemote(key); if (client == null) { client = repository.FindLocal(); } if (client == null) { throw Ensure.Exception.ArgumentOutOfRange("parameter", "Unnable to find a client with key '{0}'.", key); } DataContext = new ImageViewModel(client); ViewModel.PropertyChanged += OnViewModelPropertyChanged; ViewModel.DownloadCompleted += m => { ShowError(string.Empty); ImageList.SelectedIndex = ViewModel.Images.Count - 1; }; ViewModel.DownloadFailed += type => { switch (type) { case DownloadImageCommand.FailType.ClientError: ShowError("Downloading failed"); break; case DownloadImageCommand.FailType.Cancelled: ShowError("Downloading cancelled"); break; default: ShowError("Unknown error while downloading the image"); Debug.Fail($"Missing switch for {type}."); break; } }; ViewModel.SaveCompleted += () => ShowInfo("Saved"); ViewModel.SaveFailed += () => ShowError("Something went wrong saving the image"); ViewModel.CheckStatus.Execute(null); }
protected override async void OnNavigatedFrom(NavigationEventArgs e) { base.OnNavigatedFrom(e); await StatusBarProvider.TryExecuteAsync(async statusBar => await statusBar.ShowAsync()); }