1using Microsoft.Maui.Controls;
8 [ContentProperty(nameof(CardContent))]
11 public static readonly BindableProperty CardContentProperty = BindableProperty.Create(
16 propertyChanged: OnCardContentChanged);
18 public static readonly BindableProperty CardStyleProperty = BindableProperty.Create(
23 propertyChanged: OnCardStyleChanged);
25 public static readonly BindableProperty CardPaddingProperty = BindableProperty.Create(
30 propertyChanged: OnCardPaddingChanged);
32 public static readonly BindableProperty CardMarginProperty = BindableProperty.Create(
37 propertyChanged: OnCardMarginChanged);
39 public static readonly BindableProperty CardWidthFractionProperty = BindableProperty.Create(
44 propertyChanged: OnSizingPropertyChanged);
46 public static readonly BindableProperty CardMaxHeightFractionProperty = BindableProperty.Create(
51 propertyChanged: OnSizingPropertyChanged);
53 private readonly Border cardFrame;
54 private readonly ContentView contentHost;
58 this.contentHost =
new ContentView() { HorizontalOptions = LayoutOptions.Fill };
60 this.cardFrame =
new Border
62 HorizontalOptions = LayoutOptions.Fill,
63 VerticalOptions = LayoutOptions.Center,
65 Margin = this.CardMargin
67 this.cardFrame.Content = this.contentHost;
69 this.Placement = PopupPlacement.Center;
70 this.PopupMargin =
new Thickness(16);
71 this.StretchContentWidth =
true;
72 this.PopupContent = this.cardFrame;
74 this.SetDynamicResource(CardStyleProperty,
"PopupBorder");
76 this.SizeChanged += this.OnSizeChanged;
84 get => (View?)this.GetValue(CardContentProperty);
85 set => this.SetValue(CardContentProperty, value);
93 get => (Style?)this.GetValue(CardStyleProperty);
94 set => this.SetValue(CardStyleProperty, value);
102 get => (Thickness)this.GetValue(CardPaddingProperty);
103 set => this.SetValue(CardPaddingProperty, value);
111 get => (Thickness)this.GetValue(CardMarginProperty);
112 set => this.SetValue(CardMarginProperty, value);
120 get => (double)this.GetValue(CardWidthFractionProperty);
121 set => this.SetValue(CardWidthFractionProperty, value);
129 get => (double)this.GetValue(CardMaxHeightFractionProperty);
130 set => this.SetValue(CardMaxHeightFractionProperty, value);
133 private static void OnCardContentChanged(BindableObject bindable,
object? oldValue,
object? newValue)
136 popup.contentHost.Content = newValue as View;
139 private static void OnCardStyleChanged(BindableObject bindable,
object? oldValue,
object? newValue)
141 if (bindable is BasicPopup popup)
142 popup.cardFrame.Style = newValue as Style;
145 private static void OnCardPaddingChanged(BindableObject bindable,
object? oldValue,
object? newValue)
147 if (bindable is BasicPopup popup && newValue is Thickness padding)
148 popup.cardFrame.Padding = padding;
151 private static void OnCardMarginChanged(BindableObject bindable,
object? oldValue,
object? newValue)
153 if (bindable is BasicPopup popup && newValue is Thickness margin)
154 popup.cardFrame.Margin = margin;
157 private static void OnSizingPropertyChanged(BindableObject bindable,
object? oldValue,
object? newValue)
159 if (bindable is BasicPopup popup)
160 popup.UpdateCardSizing();
163 private void OnSizeChanged(
object? sender,
System.EventArgs e) => this.UpdateCardSizing();
165 private void UpdateCardSizing()
167 if (this.Width <= 0 || this.Height <= 0)
172 this.cardFrame.WidthRequest = maxWidth;
173 this.cardFrame.MaximumHeightRequest = maxHeight;