private async void DownloaderStateChanged(Enums.DownloadState state) { await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() => { Debug.WriteLine("State Change: " + state.ToString()); VisualStateManager.GoToState(this, state.ToString(), false); if (state == Enums.DownloadState.Done) { SizeBlock.Text = StringConverter.GetPrintSize(downloader.Message.DownloadSize); string folderPath = (await StorageManager.TryGetFolderAsync(downloader.Message.FolderToken))?.Path; if (folderPath == null) { folderPath = Strings.AppResources.GetString("FolderNotExist"); } SpeedBlock.Text = folderPath; Models.DownloaderMessage message = downloader.Message; NameBlock.Text = message.FileName + message.Extention; } else if (state == Enums.DownloadState.Prepared) { Models.DownloaderMessage message = downloader.Message; NameBlock.Text = message.FileName + message.Extention; int per = (int)((message.FileSize == null) ? 0 : (100f * message.DownloadSize / message.FileSize)); ProgressBlock.Text = (message.FileSize == null) ? "-%" : (per + "%"); Bar.Value = per; SizeBlock.Text = StringConverter.GetPrintSize(message.DownloadSize) + " / " + (message.FileSize == null ? "--" : StringConverter.GetPrintSize((long)message.FileSize)); SpeedBlock.Text = "-/s "; } }); }
private async void DownloaderStateChanged(Enums.DownloadState state) { //在后台运行(挂起或最小化)不更新UI if (((App)App.Current).InBackground) { return; } await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { if (state == Enums.DownloadState.Pause) { PauseButton.IsEnabled = false; PlayButton.IsEnabled = true; DeleteButton.IsEnabled = true; RefreshButton.IsEnabled = true; Bar.ShowPaused = true; } else if (state == Enums.DownloadState.Error) { PauseButton.IsEnabled = false; PlayButton.IsEnabled = false; DeleteButton.IsEnabled = true; RefreshButton.IsEnabled = true; Bar.ShowPaused = true; } else if (state == Enums.DownloadState.Downloading) { PauseButton.IsEnabled = true; PlayButton.IsEnabled = false; DeleteButton.IsEnabled = true; RefreshButton.IsEnabled = true; Bar.ShowPaused = false; } else if (state == Enums.DownloadState.Done) { Bar.Value = 100; ProgressBlock.Text = "100%"; PlayButton.IsEnabled = false; PauseButton.IsEnabled = false; DeleteButton.IsEnabled = false; RefreshButton.IsEnabled = false; } else if (state == Enums.DownloadState.Prepared) { HideGlassLabel.Begin(); Models.DownloaderMessage message = downloader.Message; NameBlock.Text = message.FileName + message.Extention; PauseButton.IsEnabled = false; PlayButton.IsEnabled = true; DeleteButton.IsEnabled = true; RefreshButton.IsEnabled = false; int per = (int)((message.FileSize == null) ? 0 : (100f * message.DownloadSize / message.FileSize)); ProgressBlock.Text = (message.FileSize == null) ? "-%" : (per + "%"); Bar.Value = per; SizeBlock.Text = StringConverter.GetPrintSize(message.DownloadSize) + " / " + (message.FileSize == null ? "--" : StringConverter.GetPrintSize((long)message.FileSize)); SpeedBlock.Text = "-/s "; } }); }