public void SlideRight(double velocity, System.Action callback = null) { if (velocity == 0.0) { velocity = 480.0 + 12.0; } var transform = ImagesGrid.RenderTransform as CompositeTransform; if (transform == null) { return; } var translationX = 480.0 + 12.0; var duration = PanAndZoomBehavior.Clamp((translationX - transform.TranslateX) / velocity, .15, .35); #if !NO_RIBBON Ribbon.ScrollPrevious(duration); #endif var storyboard = new Storyboard(); var translateAnimation = new DoubleAnimation(); translateAnimation.To = translationX; translateAnimation.Duration = new Duration(TimeSpan.FromSeconds(duration)); Storyboard.SetTarget(translateAnimation, transform); Storyboard.SetTargetProperty(translateAnimation, new PropertyPath("TranslateX")); storyboard.Children.Add(translateAnimation); storyboard.Begin(); //MainGrid.IsHitTestVisible = false; _slideAnimating = true; storyboard.Completed += (sender, args) => { //Deployment.Current.Dispatcher.BeginInvoke(() => // { //MainGrid.IsHitTestVisible = true; _slideAnimating = false; //}); //MainGrid.IsHitTestVisible = true; transform.TranslateX = 0.0; Grid.SetColumn(Item1, Grid.GetColumn(Item1) + 1 > 2 ? 0 : Grid.GetColumn(Item1) + 1); Grid.SetColumn(Item2, Grid.GetColumn(Item2) + 1 > 2 ? 0 : Grid.GetColumn(Item2) + 1); Grid.SetColumn(Item3, Grid.GetColumn(Item3) + 1 > 2 ? 0 : Grid.GetColumn(Item3) + 1); SetPanAndZoom(); //return; ViewModel.SlideRight(); //return; SetControlContent(0, ViewModel.PreviousItem); callback.SafeInvoke(); }; }
public void Move(double percent) { percent = PanAndZoomBehavior.Clamp(percent, -1.0, 1.0); var translateX = percent < 0.0 ? _translationX - (_minTranslationX - _translationX) * percent : _translationX + (_maxTranslationX - _translationX) * percent; //Transform.X = translateX; if (_currentImage != null) { _currentImage.Width = _currentImage.ExpandedWidth - (_currentImage.ExpandedWidth - RibbonImageControl.MinExpandedWidth) * Math.Abs(percent); } _toImage = percent < 0.0 ? _nextImage : _previousImage; if (_toImage != null) { _toImage.Width = RibbonImageControl.MinExpandedWidth + (_toImage.ExpandedWidth - RibbonImageControl.MinExpandedWidth) * Math.Abs(percent); } _toContainer = percent < 0.0 ? _nextContainer : _previousContainer; var x = 0.0; for (var i = 0; i < Items.Items.Count; i++) { ContentPresenter container; var image = FindAtIndex <RibbonImageControl>(Items, i, out container); if (container != null) { container.RenderTransform = new TranslateTransform { X = x + translateX }; x += image.Width; //if (container == _toContainer) //{ // x += _toImage.Width; //} //else if (container == _currentContainer) //{ // x += _currentImage.Width; //} //else if (container != null) //{ // x += image.Width; //} } } }
public DecryptedImageViewerView() { InitializeComponent(); OptimizeFullHD(); BuildLocalizedAppBar(); Visibility = Visibility.Collapsed; Loaded += (sender, args) => { var behaviorCollection = Interaction.GetBehaviors(Control2); if (behaviorCollection.FirstOrDefault(x => x is PanAndZoomBehavior) == null) { var panAndZoomBehavior = new PanAndZoomBehavior(); panAndZoomBehavior.MaxZoom = 5.0; panAndZoomBehavior.CanZoom = true; panAndZoomBehavior.DoubleTap += PanAndZoom_OnDoubleTap; var canZoomBinding = new Binding("CanZoom"); canZoomBinding.Source = ViewModel; BindingOperations.SetBinding(panAndZoomBehavior, PanAndZoomBehavior.CanZoomProperty, canZoomBinding); behaviorCollection.Add(panAndZoomBehavior); _panAndZoomBehavior = panAndZoomBehavior; } if (!_runOnce && ViewModel.CurrentItem != null) { _runOnce = true; BeginOpenStoryboard(); } ViewModel.PropertyChanged += OnViewModelPropertyChanged; if (!ViewModel.ShowOpenMediaListButton) { ApplicationBar.MenuItems.Remove(_openMediaMenuItem); } if (ViewModel.DialogDetails == null) { ApplicationBar.MenuItems.Remove(_deleteMenuItem); } }; Unloaded += (sender, args) => { ViewModel.PropertyChanged -= OnViewModelPropertyChanged; }; }
public ProfilePhotoViewerView() { InitializeComponent(); Visibility = Visibility.Collapsed; _savePhotoMenuItem.Click += (o, e) => ViewModel.SavePhoto(); _deletePhotoMenuItem.Click += (o, e) => ViewModel.DeletePhoto(); _sharePhotoMenuItem.Click += (o, e) => ViewModel.SharePhoto(); _setPhotoMenuItem.Click += (o, e) => ViewModel.SetPhoto(); BuildLocalizedAppBar(); OptimizeFullHD(); _runOnce = true; Loaded += (o, e) => { var behaviorCollection = Interaction.GetBehaviors(Control2); if (behaviorCollection.FirstOrDefault(x => x is PanAndZoomBehavior) == null) { var panAndZoomBehavior = new PanAndZoomBehavior(); panAndZoomBehavior.MaxZoom = 5.0; panAndZoomBehavior.CanZoom = true; panAndZoomBehavior.DoubleTap += PanAndZoom_OnDoubleTap; behaviorCollection.Add(panAndZoomBehavior); _panAndZoomBehavior = panAndZoomBehavior; } SetLocalizedAppBarButtons(); if (_runOnce && ViewModel.CurrentItem != null) { _runOnce = false; BeginOpenStoryboard(); } ViewModel.PropertyChanged += OnViewModelPropertyChanged; }; Unloaded += (o, e) => { ViewModel.PropertyChanged -= OnViewModelPropertyChanged; }; }
private void ImagesGrid_OnManipulationDelta(object sender, ManipulationDeltaEventArgs e) { e.Handled = true; if (_panAndZoomBehavior.CurrentScaleX > 1.0) { return; } if (_slideAnimating) { return; } if (_verticalDrag == null) { _verticalDrag = Math.Abs(e.DeltaManipulation.Translation.Y) > Math.Abs(e.DeltaManipulation.Translation.X); } if (_verticalDrag == false) { var transform = ImagesGrid.RenderTransform as CompositeTransform; if (transform == null) { return; } if (e.CumulativeManipulation.Translation.X < 0.0 && ViewModel.CanSlideLeft) { transform.TranslateX += e.DeltaManipulation.Translation.X; } else if (e.CumulativeManipulation.Translation.X > 0.0 && ViewModel.CanSlideRight) { transform.TranslateX += e.DeltaManipulation.Translation.X; } var percent = transform.TranslateX / 480.0; #if !NO_RIBBON Ribbon.Move(percent); #endif transform.TranslateX = PanAndZoomBehavior.Clamp(transform.TranslateX, -480.0 - 12.0, 480.0 + 12.0); _panAndZoomBehavior.IsEnabled = transform.TranslateX == 0.0; } else { var transform = ImagesGrid.RenderTransform as CompositeTransform; if (transform == null) { return; } var translate = new CompositeTransform { TranslateX = 0, TranslateY = e.CumulativeManipulation.Translation.Y }; var rootFrameHeight = ((PhoneApplicationFrame)Application.Current.RootVisual).ActualHeight; var deltaY = Math.Abs(translate.TranslateY + translate.ScaleY * transform.TranslateY + (translate.ScaleY - 1) * (transform.CenterY - translate.CenterY)); var opacity = (rootFrameHeight - deltaY) / rootFrameHeight; var backgroundBrush = (SolidColorBrush)BackgroundBorder.Background; var backgroundColor = backgroundBrush.Color; backgroundColor.A = (byte)(opacity * byte.MaxValue); BackgroundBorder.Opacity = opacity; ImagesGrid.RenderTransform = translate; _panAndZoomBehavior.IsEnabled = translate.TranslateY == 0.0; } }