protected override async void OnNavigatedTo(NavigationEventArgs e) { try { if (e.Parameter is Tuple <Frame, object> Parameters) { FileControlNav = Parameters.Item1; PhotoDisplaySupport Item = Parameters.Item2 as PhotoDisplaySupport; OriginFile = (await Item.PhotoFile.GetStorageItem().ConfigureAwait(true)) as StorageFile; OriginImage = await Item.GenerateImageWithRotation().ConfigureAwait(true); OriginBackupImage = SoftwareBitmap.Copy(OriginImage); WriteableBitmap WBitmap = new WriteableBitmap(OriginImage.PixelWidth, OriginImage.PixelHeight); OriginImage.CopyToBuffer(WBitmap.PixelBuffer); Cropper.Source = WBitmap; UnchangeRegion = Cropper.CroppedRegion; await AddEffectsToPane().ConfigureAwait(false); } } catch (Exception ex) { ExceptionTracer.RequestBlueScreen(ex); } }
private async void ImageRotate_Click(object sender, RoutedEventArgs e) { PhotoDisplaySupport Item = PhotoCollection[Flip.SelectedIndex]; if (Flip.ContainerFromItem(Item) is DependencyObject Container && Container.FindChildOfType <ScrollViewer>() is ScrollViewer Viewer) { Storyboard Story = new Storyboard(); switch (Item.RotateAngle % 360) { case 0: case 180: { DoubleAnimation WidthAnimation = new DoubleAnimation { From = Flip.ActualWidth, To = Flip.ActualHeight, Duration = TimeSpan.FromMilliseconds(500), EnableDependentAnimation = true, EasingFunction = new CircleEase { EasingMode = EasingMode.EaseOut } }; Storyboard.SetTarget(WidthAnimation, Viewer); Storyboard.SetTargetProperty(WidthAnimation, "Width"); Story.Children.Add(WidthAnimation); await Task.WhenAll(Story.BeginAsync(), Viewer.Rotate(Item.RotateAngle += 90).StartAsync()).ConfigureAwait(true); break; } case 90: case 270: { DoubleAnimation HeightAnimation = new DoubleAnimation { From = Flip.ActualHeight, To = Flip.ActualWidth, Duration = TimeSpan.FromMilliseconds(500), EnableDependentAnimation = true, EasingFunction = new CircleEase { EasingMode = EasingMode.EaseOut } }; Storyboard.SetTarget(HeightAnimation, Viewer); Storyboard.SetTargetProperty(HeightAnimation, "Width"); Story.Children.Add(HeightAnimation); await Task.WhenAll(Story.BeginAsync(), Viewer.Rotate(Item.RotateAngle += 90).StartAsync()).ConfigureAwait(true); break; } } } }
private async void ImageRotate_Click(object sender, RoutedEventArgs e) { PhotoDisplaySupport Item = PhotoCollection[Flip.SelectedIndex]; ScrollViewer Viewer = Flip.ContainerFromItem(Item).FindChildOfType <ScrollViewer>(); Viewer.RenderTransformOrigin = new Point(0.5, 0.5); await Viewer.Rotate(Item.RotateAngle += 90).StartAsync().ConfigureAwait(false); }
private async void Delete_Click(object sender, RoutedEventArgs e) { DeleteDialog Dialog = new DeleteDialog(Globalization.GetString("QueueDialog_DeleteFile_Content")); if ((await Dialog.ShowAsync().ConfigureAwait(true)) == ContentDialogResult.Primary) { PhotoDisplaySupport Item = PhotoCollection[Flip.SelectedIndex]; try { await FullTrustExcutorController.Current.DeleteAsync(Item.PhotoFile.Path, Dialog.IsPermanentDelete).ConfigureAwait(true); PhotoCollection.Remove(Item); Behavior.InitAnimation(InitOption.Full); } catch (FileCaputureException) { QueueContentDialog dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_Item_Captured_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; _ = await dialog.ShowAsync().ConfigureAwait(true); } catch (FileNotFoundException) { QueueContentDialog dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_DeleteItemError_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_RefreshButton") }; _ = await dialog.ShowAsync().ConfigureAwait(true); } catch (InvalidOperationException) { QueueContentDialog dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_DeleteFailUnexpectError_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; _ = await dialog.ShowAsync().ConfigureAwait(true); } catch (Exception) { QueueContentDialog dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_DeleteItemError_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; _ = await dialog.ShowAsync().ConfigureAwait(true); } } }
/// <summary> /// 使用动画效果更改当前显示的图片 /// </summary> /// <param name="e">需要显示的图片</param> private void ChangeDisplayImage(PhotoDisplaySupport e) { FileName.Text = e.FileName; DisplayFile = e.PhotoFile; DisplayImage.Opacity = 0; Image image = ((ImageList.ContainerFromItem(e) as ListViewItem).ContentTemplateRoot as FrameworkElement).FindName("Photo") as Image; ConnectedAnimationService.GetForCurrentView().PrepareToAnimate("PhotoAnimation", image).Configuration = new BasicConnectedAnimationConfiguration(); ConnectedAnimationService.GetForCurrentView().DefaultDuration = TimeSpan.FromMilliseconds(600); FadeOut.Begin(); SelectedPhotoID = e.PhotoFile.FolderRelativeId; }
private async void Delete_Click(object sender, RoutedEventArgs e) { try { PhotoDisplaySupport Item = PhotoCollection[Flip.SelectedIndex]; Item.PhotoFile.PermanentDelete(); PhotoCollection.Remove(Item); Behavior.InitAnimation(InitOption.Full); } catch (Exception) { QueueContentDialog dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_DeleteItemError_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; _ = await dialog.ShowAsync().ConfigureAwait(true); } }
private async void USBPhotoViewer_Loaded(object sender, RoutedEventArgs e) { PhotoCollection = new ObservableCollection <PhotoDisplaySupport>(); ImageList.ItemsSource = PhotoCollection; QueryOptions Options = new QueryOptions(CommonFileQuery.DefaultQuery, null) { FolderDepth = FolderDepth.Shallow, IndexerOption = IndexerOption.UseIndexerWhenAvailable }; Options.SetThumbnailPrefetch(ThumbnailMode.PicturesView, 250, ThumbnailOptions.ResizeThumbnail); StorageFileQueryResult QueryResult = USBControl.ThisPage.CurrentFolder.CreateFileQueryWithOptions(Options); var FileCollection = await QueryResult.GetFilesAsync(); PhotoDisplaySupport SelectedPhoto = null; foreach (StorageFile File in FileCollection.Where(File => File.FileType == ".png" || File.FileType == ".jpg" || File.FileType == ".jpeg" || File.FileType == ".bmp").Select(File => File)) { using (var Thumbnail = await File.GetThumbnailAsync(ThumbnailMode.PicturesView)) { PhotoCollection.Add(new PhotoDisplaySupport(Thumbnail, File)); } if (File.FolderRelativeId == SelectedPhotoID) { SelectedPhoto = PhotoCollection.Last(); } } await Task.Delay(800); ImageList.ScrollIntoViewSmoothly(SelectedPhoto, ScrollIntoViewAlignment.Leading); ImageList.SelectedItem = SelectedPhoto; await Task.Delay(500); ChangeDisplayImage(ImageList.SelectedItem as PhotoDisplaySupport); }
private async void Delete_Click(object sender, RoutedEventArgs e) { if (Window.Current.CoreWindow.GetKeyState(VirtualKey.Shift).HasFlag(CoreVirtualKeyStates.Down)) { PhotoDisplaySupport Item = PhotoCollection[Flip.SelectedIndex]; Retry: try { await FullTrustProcessController.Current.DeleteAsync(Item.PhotoFile.Path, true).ConfigureAwait(true); PhotoCollection.Remove(Item); Behavior.InitAnimation(InitOption.Full); } catch (FileCaputureException) { QueueContentDialog dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_Item_Captured_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; _ = await dialog.ShowAsync().ConfigureAwait(true); } catch (FileNotFoundException) { QueueContentDialog dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_DeleteItemError_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_RefreshButton") }; _ = await dialog.ShowAsync().ConfigureAwait(true); } catch (InvalidOperationException) { QueueContentDialog dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_UnauthorizedDelete_Content"), PrimaryButtonText = Globalization.GetString("Common_Dialog_GrantButton"), CloseButtonText = Globalization.GetString("Common_Dialog_CancelButton") }; if (await dialog.ShowAsync().ConfigureAwait(true) == ContentDialogResult.Primary) { if (await FullTrustProcessController.Current.SwitchToAdminModeAsync().ConfigureAwait(true)) { goto Retry; } else { QueueContentDialog ErrorDialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_DenyElevation_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; _ = await ErrorDialog.ShowAsync().ConfigureAwait(true); } } } catch (Exception) { QueueContentDialog dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_DeleteItemError_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; _ = await dialog.ShowAsync().ConfigureAwait(true); } } else { DeleteDialog Dialog = new DeleteDialog(Globalization.GetString("QueueDialog_DeleteFile_Content")); if ((await Dialog.ShowAsync().ConfigureAwait(true)) == ContentDialogResult.Primary) { PhotoDisplaySupport Item = PhotoCollection[Flip.SelectedIndex]; Retry: try { await FullTrustProcessController.Current.DeleteAsync(Item.PhotoFile.Path, Dialog.IsPermanentDelete).ConfigureAwait(true); PhotoCollection.Remove(Item); Behavior.InitAnimation(InitOption.Full); } catch (FileCaputureException) { QueueContentDialog dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_Item_Captured_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; _ = await dialog.ShowAsync().ConfigureAwait(true); } catch (FileNotFoundException) { QueueContentDialog dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_DeleteItemError_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_RefreshButton") }; _ = await dialog.ShowAsync().ConfigureAwait(true); } catch (InvalidOperationException) { QueueContentDialog dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_UnauthorizedDelete_Content"), PrimaryButtonText = Globalization.GetString("Common_Dialog_GrantButton"), CloseButtonText = Globalization.GetString("Common_Dialog_CancelButton") }; if (await dialog.ShowAsync().ConfigureAwait(true) == ContentDialogResult.Primary) { if (await FullTrustProcessController.Current.SwitchToAdminModeAsync().ConfigureAwait(true)) { goto Retry; } else { QueueContentDialog ErrorDialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_DenyElevation_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; _ = await ErrorDialog.ShowAsync().ConfigureAwait(true); } } } catch (Exception) { QueueContentDialog dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_DeleteItemError_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; _ = await dialog.ShowAsync().ConfigureAwait(true); } } } }
private async void ImageRotate_Click(object sender, RoutedEventArgs e) { PhotoDisplaySupport Item = PhotoCollection[Flip.SelectedIndex]; if (Flip.ContainerFromItem(Item) is DependencyObject Container && Container.FindChildOfType <ScrollViewer>() is ScrollViewer Viewer) { switch (Item.RotateAngle % 360) { case 0: case 180: { DoubleAnimation WidthAnimation = new DoubleAnimation { From = Flip.ActualWidth, To = Flip.ActualHeight, Duration = TimeSpan.FromMilliseconds(500), EnableDependentAnimation = true, EasingFunction = new CubicEase { EasingMode = EasingMode.EaseOut } }; Storyboard.SetTarget(WidthAnimation, Viewer); Storyboard.SetTargetProperty(WidthAnimation, "Width"); Vector2 StartRotationCenter = new Vector2(Convert.ToSingle(Flip.ActualWidth / 2), Convert.ToSingle(Flip.ActualHeight / 2)); Vector2 EndRotationCenter = new Vector2(Convert.ToSingle(Flip.ActualHeight / 2), Convert.ToSingle(Flip.ActualHeight / 2)); await AnimationBuilder.Create() .CenterPoint(EndRotationCenter, StartRotationCenter, duration: TimeSpan.FromMilliseconds(500), easingType: EasingType.Cubic, easingMode: EasingMode.EaseOut) .ExternalAnimation(WidthAnimation) .RotationInDegrees(Item.RotateAngle += 90, duration: TimeSpan.FromMilliseconds(500), easingType: EasingType.Cubic, easingMode: EasingMode.EaseOut) .StartAsync(Viewer); break; } case 90: case 270: { DoubleAnimation HeightAnimation = new DoubleAnimation { From = Flip.ActualHeight, To = Flip.ActualWidth, Duration = TimeSpan.FromMilliseconds(500), EnableDependentAnimation = true, EasingFunction = new CubicEase { EasingMode = EasingMode.EaseOut } }; Storyboard.SetTarget(HeightAnimation, Viewer); Storyboard.SetTargetProperty(HeightAnimation, "Width"); Vector2 StartRotationCenter = new Vector2(Convert.ToSingle(Flip.ActualHeight / 2), Convert.ToSingle(Flip.ActualHeight / 2)); Vector2 EndRotationCenter = new Vector2(Convert.ToSingle(Flip.ActualWidth / 2), Convert.ToSingle(Flip.ActualHeight / 2)); await AnimationBuilder.Create() .CenterPoint(EndRotationCenter, StartRotationCenter, duration: TimeSpan.FromMilliseconds(500), easingType: EasingType.Cubic, easingMode: EasingMode.EaseOut) .ExternalAnimation(HeightAnimation) .RotationInDegrees(Item.RotateAngle += 90, duration: TimeSpan.FromMilliseconds(500), easingType: EasingType.Cubic, easingMode: EasingMode.EaseOut) .StartAsync(Viewer); break; } } } }