using Gallery.Util.Model; using Xamarin.Forms; namespace Gallery.Resources.UI { public class CardView : ContentView { public static readonly BindableProperty CornerRadiusProperty = BindableProperty.Create(nameof(CornerRadius), typeof(float), typeof(CardView)); public static readonly BindableProperty ShadowColorProperty = BindableProperty.Create(nameof(ShadowColor), typeof(Color), typeof(CardView)); public static readonly BindableProperty ShadowRadiusProperty = BindableProperty.Create(nameof(ShadowRadius), typeof(float), typeof(CardView), 3f); public static readonly BindableProperty ShadowOffsetProperty = BindableProperty.Create(nameof(ShadowOffset), typeof(Size), typeof(CardView)); public float CornerRadius { get => (float)GetValue(CornerRadiusProperty); set => SetValue(CornerRadiusProperty, value); } public Color ShadowColor { get => (Color)GetValue(ShadowColorProperty); set => SetValue(ShadowColorProperty, value); } public float ShadowRadius { get => (float)GetValue(ShadowRadiusProperty); set => SetValue(ShadowRadiusProperty, value); } public Size ShadowOffset { get => (Size)GetValue(ShadowOffsetProperty); set => SetValue(ShadowOffsetProperty, value); } protected override SizeRequest OnMeasure(double widthConstraint, double heightConstraint) { if (BindingContext is GalleryItem item && item.Width > 0 && item.ImageHeight.IsAuto) { item.ImageHeight = widthConstraint * item.Height / item.Width; } return base.OnMeasure(widthConstraint, heightConstraint); } } }