// 进入VideoDetailsPage protected async override void OnNavigatedTo(NavigationEventArgs e) { LoadingControl.IsLoading = true; viewmodel = FolderViewModel.GetInstance(); foreach (var video in viewmodel.LikeVideos) { if (video.Name == viewmodel.SelectedVideo.Name) { LikeButton.Content = "取消收藏"; break; } } StorageFile VideoFile = await Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.GetFileAsync(viewmodel.SelectedVideo.Token); if (VideoFile != null) { var stream = await VideoFile.OpenAsync(Windows.Storage.FileAccessMode.Read); mediaElement.SetSource(stream, VideoFile.ContentType); } StarsRating.Value = (double)viewmodel.SelectedVideo.Stars; if (viewmodel.SelectedVideo.NotePath != "") { StorageFolder folder = ApplicationData.Current.LocalFolder; StorageFile file = await folder.GetFileAsync(viewmodel.SelectedVideo.Name + ".rtf"); if (file != null) { try { Windows.Storage.Streams.IRandomAccessStream randAccStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read); // Load the file into the Document property of the RichEditBox. EditZone.Document.LoadFromStream(Windows.UI.Text.TextSetOptions.FormatRtf, randAccStream); } catch (Exception) { ContentDialog errorDialog = new ContentDialog() { Title = "File open error", Content = "Sorry, I couldn't open the file.", PrimaryButtonText = "Ok" }; await errorDialog.ShowAsync(); } } } viewmodel.VideoAdd(); videoName.Text = viewmodel.SelectedVideo.Name; }
protected override void OnNavigatedTo(NavigationEventArgs e) { //Frame rootFrame = Window.Current.Content as Frame; //SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = rootFrame.CanGoBack ? // AppViewBackButtonVisibility.Visible : Windows.UI.Core.AppViewBackButtonVisibility.Collapsed; //base.OnNavigatedTo(e); viewModel = FolderViewModel.GetInstance(); // folders拷贝viewmodel中的folders用于与数据库关联 folders = viewModel.Folders; // videos不需要保存到数据库中,每次打开页面都把文件夹下的文件读出来即可 foreach (var eachfolder in folders) { showVideoInFolder(eachfolder.Token); } // 挂起 }
/// <summary> /// 重载函数处理传入参数 /// </summary> /// <param name="e">Folder类型,为即将显示的界面的根目录</param> protected async override void OnNavigatedTo(NavigationEventArgs e) { //SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = Frame.CanGoBack ? // AppViewBackButtonVisibility.Visible : Windows.UI.Core.AppViewBackButtonVisibility.Collapsed; //base.OnNavigatedTo(e); MainStackPanel.Visibility = Visibility.Collapsed; EmptyFolderText.Visibility = Visibility.Visible; viewModel = FolderViewModel.GetInstance(); // 就是currentFolder = e.parameter as folder 然后判断一下不为null if (e.Parameter is Folder currentFolder) { currentRootFolder = currentFolder; try { folders.Clear(); bool wheatherShowEmpty = true; var folder = await Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.GetFolderAsync(currentRootFolder.Token); if (folder != null) { var foldersQuery = folder.CreateFolderQuery(); foreach (var eachfolder in await foldersQuery.GetFoldersAsync()) { wheatherShowEmpty = false; string token = Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.Add(eachfolder); folders.Add(new Folder(token, eachfolder.Name, await GetNumInFolder(eachfolder))); } var filesQuery = new Windows.Storage.Search.QueryOptions(); filesQuery.FileTypeFilter.Add(".mp4"); filesQuery.FileTypeFilter.Add(".wma"); filesQuery.FileTypeFilter.Add(".avi"); var query = folder.CreateFileQueryWithOptions(filesQuery); var files = await query.GetFilesAsync(); foreach (var file in files) { BitmapImage bitmapImage = await Common.GetThumbnailOfVideo(file); wheatherShowEmpty = false; Video temp = await viewModel.Search(file.Path); string videoToken; string date = DateTimeOffset.Now.Year.ToString() + "/" + DateTimeOffset.Now.Month.ToString() + "/" + DateTimeOffset.Now.Day.ToString(); if (temp == null) { videoToken = Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.Add(file); videos.Add(new Video(videoToken, file.Name, date, "", 0, 0, 0, 0, file.Path, bitmapImage)); } else { temp.Date = date; videos.Add(temp); } } } if (!wheatherShowEmpty) { MainStackPanel.Visibility = Visibility.Visible; EmptyFolderText.Visibility = Visibility.Collapsed; } } catch (Exception) { await new MessageDialog("Path is not valid").ShowAsync(); } } }
protected override void OnNavigatedTo(NavigationEventArgs e) { viewModel = FolderViewModel.GetInstance(); histories = viewModel.Histories; }
protected override void OnNavigatedTo(NavigationEventArgs e) { viewmodel = FolderViewModel.GetInstance(); likes = viewmodel.LikeVideos; }