Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
BasicPopup.cs
1using Microsoft.Maui.Controls;
2
4{
8 [ContentProperty(nameof(CardContent))]
9 public class BasicPopup : BasePopupView
10 {
11 public static readonly BindableProperty CardContentProperty = BindableProperty.Create(
12 nameof(CardContent),
13 typeof(View),
14 typeof(BasicPopup),
15 null,
16 propertyChanged: OnCardContentChanged);
17
18 public static readonly BindableProperty CardStyleProperty = BindableProperty.Create(
19 nameof(CardStyle),
20 typeof(Style),
21 typeof(BasicPopup),
22 null,
23 propertyChanged: OnCardStyleChanged);
24
25 public static readonly BindableProperty CardPaddingProperty = BindableProperty.Create(
26 nameof(CardPadding),
27 typeof(Thickness),
28 typeof(BasicPopup),
29 new Thickness(16),
30 propertyChanged: OnCardPaddingChanged);
31
32 public static readonly BindableProperty CardMarginProperty = BindableProperty.Create(
33 nameof(CardMargin),
34 typeof(Thickness),
35 typeof(BasicPopup),
36 new Thickness(0),
37 propertyChanged: OnCardMarginChanged);
38
39 public static readonly BindableProperty CardWidthFractionProperty = BindableProperty.Create(
40 nameof(CardWidthFraction),
41 typeof(double),
42 typeof(BasicPopup),
43 0.875,
44 propertyChanged: OnSizingPropertyChanged);
45
46 public static readonly BindableProperty CardMaxHeightFractionProperty = BindableProperty.Create(
48 typeof(double),
49 typeof(BasicPopup),
50 0.8,
51 propertyChanged: OnSizingPropertyChanged);
52
53 private readonly Border cardFrame;
54 private readonly ContentView contentHost;
55
56 public BasicPopup()
57 {
58 this.contentHost = new ContentView() { HorizontalOptions = LayoutOptions.Fill };
59
60 this.cardFrame = new Border
61 {
62 HorizontalOptions = LayoutOptions.Fill,
63 VerticalOptions = LayoutOptions.Center,
64 Padding = this.CardPadding,
65 Margin = this.CardMargin
66 };
67 this.cardFrame.Content = this.contentHost;
68
69 this.Placement = PopupPlacement.Center;
70 this.PopupMargin = new Thickness(16);
71 this.StretchContentWidth = true;
72 this.PopupContent = this.cardFrame;
73
74 this.SetDynamicResource(CardStyleProperty, "PopupBorder");
75
76 this.SizeChanged += this.OnSizeChanged;
77 }
78
82 public View? CardContent
83 {
84 get => (View?)this.GetValue(CardContentProperty);
85 set => this.SetValue(CardContentProperty, value);
86 }
87
91 public Style? CardStyle
92 {
93 get => (Style?)this.GetValue(CardStyleProperty);
94 set => this.SetValue(CardStyleProperty, value);
95 }
96
100 public Thickness CardPadding
101 {
102 get => (Thickness)this.GetValue(CardPaddingProperty);
103 set => this.SetValue(CardPaddingProperty, value);
104 }
105
109 public Thickness CardMargin
110 {
111 get => (Thickness)this.GetValue(CardMarginProperty);
112 set => this.SetValue(CardMarginProperty, value);
113 }
114
118 public double CardWidthFraction
119 {
120 get => (double)this.GetValue(CardWidthFractionProperty);
121 set => this.SetValue(CardWidthFractionProperty, value);
122 }
123
128 {
129 get => (double)this.GetValue(CardMaxHeightFractionProperty);
130 set => this.SetValue(CardMaxHeightFractionProperty, value);
131 }
132
133 private static void OnCardContentChanged(BindableObject bindable, object? oldValue, object? newValue)
134 {
135 if (bindable is BasicPopup popup)
136 popup.contentHost.Content = newValue as View;
137 }
138
139 private static void OnCardStyleChanged(BindableObject bindable, object? oldValue, object? newValue)
140 {
141 if (bindable is BasicPopup popup)
142 popup.cardFrame.Style = newValue as Style;
143 }
144
145 private static void OnCardPaddingChanged(BindableObject bindable, object? oldValue, object? newValue)
146 {
147 if (bindable is BasicPopup popup && newValue is Thickness padding)
148 popup.cardFrame.Padding = padding;
149 }
150
151 private static void OnCardMarginChanged(BindableObject bindable, object? oldValue, object? newValue)
152 {
153 if (bindable is BasicPopup popup && newValue is Thickness margin)
154 popup.cardFrame.Margin = margin;
155 }
156
157 private static void OnSizingPropertyChanged(BindableObject bindable, object? oldValue, object? newValue)
158 {
159 if (bindable is BasicPopup popup)
160 popup.UpdateCardSizing();
161 }
162
163 private void OnSizeChanged(object? sender, System.EventArgs e) => this.UpdateCardSizing();
164
165 private void UpdateCardSizing()
166 {
167 if (this.Width <= 0 || this.Height <= 0)
168 return;
169
170 double maxWidth = this.Width * this.CardWidthFraction;
171 double maxHeight = this.Height * this.CardMaxHeightFraction;
172 this.cardFrame.WidthRequest = maxWidth;
173 this.cardFrame.MaximumHeightRequest = maxHeight;
174 }
175 }
176}
Flexible popup surface capable of positioning its content in different regions of the screen.
Provides a centered card layout with configurable sizing constraints.
Definition: BasicPopup.cs:10
double CardWidthFraction
Fraction of available width used as the maximum card width.
Definition: BasicPopup.cs:119
View? CardContent
Content presented inside the centered card.
Definition: BasicPopup.cs:83
Thickness CardMargin
Margin applied around the card frame.
Definition: BasicPopup.cs:110
Style? CardStyle
Optional style applied to the card Border.
Definition: BasicPopup.cs:92
Thickness CardPadding
Padding inside the card frame.
Definition: BasicPopup.cs:101
double CardMaxHeightFraction
Fraction of available height used as the maximum card height.
Definition: BasicPopup.cs:128