/// <summary> /// Since Xamarin does not remove default transformations, we need to simply remove and create new AtomZoomView /// with new AtomImage /// </summary> private void RecreateImage() { this.IsClippedToBounds = false; croppedImage.PropertyChanged -= OnImagePropertyChanged; zoomView.PropertyChanged -= OnZoomViewPropertyChanged; cropContainer.Children.Remove(zoomView); //Debug.WriteLine($"zoomView is reset correctly"); zoomView = new AtomZoomView(); croppedImage = new AtomImage(); croppedImage.PropertyChanged += OnImagePropertyChanged; zoomView.PropertyChanged += OnZoomViewPropertyChanged; zoomView.Content = croppedImage; cropContainer.Children.Add(zoomView); zoomView.SetBinding(AtomZoomView.IsEnabledProperty, new Binding() { Path = nameof(CanUndo), Source = this, Converter = NegateBooleanConverter.Instance }); }
//ScrollView scrollView = new ScrollView(); public AtomImageCropper() { //this.Padding = new Thickness(10); //Children.Add(zoomView); //croppedImage.Margin = new Thickness(320, 320, 320, 320); //zoomView.Padding = new Thickness(320, 320, 320, 320); maskView.SetBinding(AtomMaskBox.BackgroundColorProperty, new Binding { Path = nameof(CropMarginColor), Source = this }); zoomView.Content = croppedImage; zoomView.SetBinding(AtomZoomView.IsEnabledProperty, new Binding() { Path = nameof(CanUndo), Source = this, Converter = NegateBooleanConverter.Instance }); //cropContainer.Content = zoomView; cropContainer.Children.Add(zoomView); cropContainer.HorizontalOptions = LayoutOptions.Center; cropContainer.VerticalOptions = LayoutOptions.Center; //cropContainer.BackgroundColor = Color.Red; cropContainer.SetBinding(Grid.BackgroundColorProperty, new Binding { Path = nameof(CropErrorColor), Source = this }); Children.Add(cropContainer); Children.Add(maskView); //this.Margin = new Thickness(50, 50, 50, 50); //this.IsClippedToBounds = true; croppedImage.PropertyChanged += OnImagePropertyChanged; cropContainer.PropertyChanged += OnCropContainerPropertyChanged; zoomView.PropertyChanged += OnZoomViewPropertyChanged; //ResizeCropContainer(); CropCommand = new AtomCommand(async() => { await OnCropCommandAsync(); }); UndoCommand = new AtomCommand(() => { // try to delete... System.IO.File.Delete(CroppedFile); CroppedFile = null; Source = originalSource; originalSource = null; CanUndo = false; return(Task.CompletedTask); }); }