private async void Element_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { this.TintColor = MaitLibs.XamarinForms.ImageTintEffect.Shared.TintEffect.GetTintColor(this.Element); try { if (this.effectBrush != null) { if (this.TintColor == Color.Transparent) { //Turn off tinting - need to redraw brush effectBrush = null; spriteVisual = null; } else { SetTint(GetNativeColor(this.TintColor)); return; } } bool needsResizing = false; needsResizing = e.PropertyName == VisualElement.XProperty.PropertyName || e.PropertyName == VisualElement.YProperty.PropertyName || e.PropertyName == VisualElement.WidthProperty.PropertyName || e.PropertyName == VisualElement.HeightProperty.PropertyName || e.PropertyName == VisualElement.ScaleProperty.PropertyName || e.PropertyName == VisualElement.TranslationXProperty.PropertyName || e.PropertyName == VisualElement.TranslationYProperty.PropertyName || e.PropertyName == VisualElement.RotationYProperty.PropertyName || e.PropertyName == VisualElement.RotationXProperty.PropertyName || e.PropertyName == VisualElement.RotationProperty.PropertyName || e.PropertyName == VisualElement.AnchorXProperty.PropertyName || e.PropertyName == VisualElement.AnchorYProperty.PropertyName; VisualElement element = this.Element as VisualElement; if (spriteVisual != null && imageSurface != null && needsResizing) { //Resizing Sprite Visual and Image Surface spriteVisual.Size = new Vector2((float)element.Width, (float)element.Height); imageSurface.Resize(new Windows.Foundation.Size(element.Width, element.Height)); return; } if (e.PropertyName == Xamarin.Forms.Image.SourceProperty.PropertyName || spriteVisual == null || (effectBrush == null && this.TintColor != Color.Transparent)) { await CreateTintEffectBrushAsync(new Uri($"ms-appx:///{((FileImageSource)(this.Element as Xamarin.Forms.Image).Source).File}")); } } catch (Exception ex) { Debug.WriteLine($"Unable to create Tinted Image. Exception: {ex.Message}"); } }
protected override async void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e) { base.OnElementPropertyChanged(sender, e); try { if (effectBrush != null && e.PropertyName == TintedImage.TintColorProperty.PropertyName) { if (((TintedImage)Element).TintColor == Color.Transparent) { //Turn off tinting - need to redraw brush effectBrush = null; spriteVisual = null; } else { SetTint(GetNativeColor(((TintedImage)Element).TintColor)); return; } } bool needsResizing = e.PropertyName == VisualElement.XProperty.PropertyName || e.PropertyName == VisualElement.YProperty.PropertyName || e.PropertyName == VisualElement.WidthProperty.PropertyName || e.PropertyName == VisualElement.HeightProperty.PropertyName || e.PropertyName == VisualElement.ScaleProperty.PropertyName || e.PropertyName == VisualElement.TranslationXProperty.PropertyName || e.PropertyName == VisualElement.TranslationYProperty.PropertyName || e.PropertyName == VisualElement.RotationYProperty.PropertyName || e.PropertyName == VisualElement.RotationXProperty.PropertyName || e.PropertyName == VisualElement.RotationProperty.PropertyName || e.PropertyName == VisualElement.AnchorXProperty.PropertyName || e.PropertyName == VisualElement.AnchorYProperty.PropertyName; if (spriteVisual != null && imageSurface != null && needsResizing) { //Resizing Sprite Visual and Image Surface spriteVisual.Size = new Vector2((float)Element.Width, (float)Element.Height); imageSurface.Resize(new Size(Element.Width, Element.Height)); return; } if (e.PropertyName == Image.SourceProperty.PropertyName || spriteVisual == null || (effectBrush == null && ((TintedImage)Element).TintColor != Color.Transparent)) { await CreateTintEffectBrushAsync(new Uri($"ms-appx:///{((FileImageSource)Element.Source).File}")); } } catch (Exception ex) { Debug.WriteLine($"Unable to create Tinted Image. Exception: {ex.Message}"); } }
protected async override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e) { base.OnElementPropertyChanged(sender, e); try { if (effectBrush != null && e.PropertyName == TintedImage.TintColorProperty.PropertyName) { SetTint(GetNativeColor(((TintedImage)Element).TintColor)); return; } bool redrawBrush = e.PropertyName == VisualElement.XProperty.PropertyName || e.PropertyName == VisualElement.YProperty.PropertyName || e.PropertyName == VisualElement.WidthProperty.PropertyName || e.PropertyName == VisualElement.HeightProperty.PropertyName || e.PropertyName == VisualElement.ScaleProperty.PropertyName || e.PropertyName == VisualElement.TranslationXProperty.PropertyName || e.PropertyName == VisualElement.TranslationYProperty.PropertyName || e.PropertyName == VisualElement.RotationYProperty.PropertyName || e.PropertyName == VisualElement.RotationXProperty.PropertyName || e.PropertyName == VisualElement.RotationProperty.PropertyName || e.PropertyName == VisualElement.AnchorXProperty.PropertyName || e.PropertyName == VisualElement.AnchorYProperty.PropertyName; if (spriteVisual != null && imageSurface != null && redrawBrush) { Debug.WriteLine($"Resizing Sprite Visual and Image Surface for {e.PropertyName} Property"); spriteVisual.Size = new Vector2((float)Element.Width, (float)Element.Height); imageSurface.Resize(new Size(Element.Width, Element.Height)); return; } if ((spriteVisual == null && effectBrush == null) || e.PropertyName == Image.SourceProperty.PropertyName) { await CreateTintEffectBrushAsync(new Uri($"ms-appx:///{((FileImageSource)Element.Source).File}")); } } catch (Exception ex) { Debug.WriteLine($"Unable to create Tinted Image. Exception: {ex.Message}"); } }