Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ParameterProtectionIndicator.cs
1using Microsoft.Maui.Controls;
2using Microsoft.Maui.Controls.Shapes;
5using Path = Microsoft.Maui.Controls.Shapes.Path;
6
8{
12 public class ParameterProtectionIndicator : ContentView
13 {
17 public static readonly BindableProperty IsTransientProperty =
18 BindableProperty.Create(
19 nameof(IsTransient),
20 typeof(bool),
22 false);
23
27 public static readonly BindableProperty IsEncryptedProperty =
28 BindableProperty.Create(
29 nameof(IsEncrypted),
30 typeof(bool),
32 false);
33
37 public static readonly BindableProperty TransientTextProperty =
38 BindableProperty.Create(
39 nameof(TransientText),
40 typeof(string),
42 string.Empty,
43 BindingMode.TwoWay,
44 defaultValueCreator: bindable => ServiceRef.Localizer[nameof(AppResources.Transient)].ToString());
45
49 public static readonly BindableProperty EncryptedTextProperty =
50 BindableProperty.Create(
51 nameof(EncryptedText),
52 typeof(string),
54 string.Empty,
55 BindingMode.TwoWay,
56 defaultValueCreator: bindable => ServiceRef.Localizer[nameof(AppResources.Encrypted)].ToString());
57
61 public bool IsTransient
62 {
63 get => (bool)this.GetValue(IsTransientProperty);
64 set => this.SetValue(IsTransientProperty, value);
65 }
66
70 public bool IsEncrypted
71 {
72 get => (bool)this.GetValue(IsEncryptedProperty);
73 set => this.SetValue(IsEncryptedProperty, value);
74 }
75
79 public string? TransientText
80 {
81 get => (string)this.GetValue(TransientTextProperty);
82 set => this.SetValue(TransientTextProperty, value);
83 }
84
88 public string? EncryptedText
89 {
90 get => (string)this.GetValue(EncryptedTextProperty);
91 set => this.SetValue(EncryptedTextProperty, value);
92 }
93
98 {
99 // Define local styles for use within this control
100 Style TransientBorderStyle = new Style(typeof(Border))
101 {
102 BasedOn = AppStyles.RoundedBorder,
103 Setters =
104 {
105 new Setter { Property = BackgroundColorProperty, Value = AppColors.Purple15 },
106 new Setter { Property = Border.PaddingProperty, Value = new Thickness(AppStyles.SmallSpacing, AppStyles.SmallSpacing/2) }
107 }
108 };
109
110 Style EncryptedBorderStyle = new Style(typeof(Border))
111 {
112 BasedOn = AppStyles.RoundedBorder,
113 Setters =
114 {
115 new Setter { Property = BackgroundColorProperty, Value = AppColors.Blue20Affirm },
116 new Setter { Property = Border.PaddingProperty, Value = new Thickness(AppStyles.SmallSpacing, AppStyles.SmallSpacing/2) }
117 }
118 };
119
120 Style TransientPathStyle = new Style(typeof(Path))
121 {
122 Setters =
123 {
124 new Setter { Property = Shape.FillProperty, Value = AppColors.Purple },
125 new Setter { Property = VerticalOptionsProperty, Value = LayoutOptions.Fill },
126 new Setter { Property = HorizontalOptionsProperty, Value = LayoutOptions.Fill },
127 new Setter { Property = Shape.AspectProperty, Value = Stretch.Uniform },
128 new Setter { Property = WidthRequestProperty, Value = 18 },
129 new Setter { Property = HeightRequestProperty, Value = 18 }
130 }
131 };
132
133 Style EncryptedPathStyle = new Style(typeof(Path))
134 {
135 Setters =
136 {
137 new Setter { Property = Shape.FillProperty, Value = AppColors.Blue }, // Example color
138 new Setter { Property = VerticalOptionsProperty, Value = LayoutOptions.Fill },
139 new Setter { Property = HorizontalOptionsProperty, Value = LayoutOptions.Fill },
140 new Setter { Property = Shape.AspectProperty, Value = Stretch.Uniform },
141 new Setter { Property = WidthRequestProperty, Value = 18 },
142 new Setter { Property = HeightRequestProperty, Value = 18 }
143 }
144 };
145
146 Style TransientLabelStyle = new Style(typeof(Label))
147 {
148 Setters =
149 {
150 new Setter { Property = Label.TextColorProperty, Value = AppColors.Purple },
151 new Setter { Property = Label.FontSizeProperty, Value = 15 },
152 new Setter { Property = Label.LineBreakModeProperty, Value = LineBreakMode.WordWrap },
153 new Setter { Property = Label.VerticalTextAlignmentProperty, Value = TextAlignment.Center },
154 new Setter { Property = Label.HorizontalTextAlignmentProperty, Value = TextAlignment.Center }
155 }
156 };
157
158 Style EncryptedLabelStyle = new Style(typeof(Label))
159 {
160 Setters =
161 {
162 new Setter { Property = Label.TextColorProperty, Value = AppColors.Blue },
163 new Setter { Property = Label.FontSizeProperty, Value = 15 },
164 new Setter { Property = Label.LineBreakModeProperty, Value = LineBreakMode.WordWrap },
165 new Setter { Property = Label.VerticalTextAlignmentProperty, Value = TextAlignment.Center },
166 new Setter { Property = Label.HorizontalTextAlignmentProperty, Value = TextAlignment.Center }
167 }
168 };
169
170 // Create a grid to hold the status indicators
171 Grid StatusGrid = new Grid
172 {
173 ColumnDefinitions =
174 {
175 new ColumnDefinition { Width = GridLength.Auto },
176 new ColumnDefinition { Width = GridLength.Auto }
177 },
178 ColumnSpacing = AppStyles.SmallSpacing
179 };
180
181 // Transient Border
182 Border TransientBorder = new Border
183 {
184 Style = TransientBorderStyle
185 };
186 TransientBorder.SetBinding(IsVisibleProperty, new Binding(nameof(this.IsTransient), source: this));
187
188 Grid TransientInnerGrid = new Grid
189 {
190 ColumnDefinitions =
191 {
192 new ColumnDefinition { Width = GridLength.Auto },
193 new ColumnDefinition { Width = GridLength.Auto }
194 },
195 ColumnSpacing = AppStyles.SmallSpacing
196 };
197
198 Path TransientPath = new Path
199 {
200 Style = TransientPathStyle,
201 // Assuming geometry data is defined here
202 Data = Geometries.VisibilityOffPath
203 };
204
205 Label TransientLabel = new Label
206 {
207 Style = TransientLabelStyle,
208 };
209 TransientLabel.SetBinding(Label.TextProperty, new Binding(nameof(this.TransientText), source: this));
210
211 Grid.SetColumn(TransientPath, 0);
212 Grid.SetColumn(TransientLabel, 1);
213
214 TransientInnerGrid.Children.Add(TransientPath);
215 TransientInnerGrid.Children.Add(TransientLabel);
216 TransientBorder.Content = TransientInnerGrid;
217
218 // Encrypted Border
219 Border EncryptedBorder = new Border
220 {
221 Style = EncryptedBorderStyle
222 };
223 EncryptedBorder.SetBinding(IsVisibleProperty, new Binding(nameof(this.IsEncrypted), source: this));
224
225 Grid EncryptedInnerGrid = new Grid
226 {
227 ColumnDefinitions =
228 {
229 new ColumnDefinition { Width = GridLength.Auto },
230 new ColumnDefinition { Width = GridLength.Auto }
231 },
232 ColumnSpacing = AppStyles.SmallSpacing
233 };
234
235 Path EncryptedPath = new Path
236 {
237 Style = EncryptedPathStyle,
238 Data = Geometries.LockPath
239 };
240
241 Label EncryptedLabel = new Label
242 {
243 Style = EncryptedLabelStyle,
244 };
245 EncryptedLabel.SetBinding(Label.TextProperty, new Binding(nameof(this.EncryptedText), source: this));
246
247 Grid.SetColumn(EncryptedPath, 0);
248 Grid.SetColumn(EncryptedLabel, 1);
249
250 EncryptedInnerGrid.Children.Add(EncryptedPath);
251 EncryptedInnerGrid.Children.Add(EncryptedLabel);
252 EncryptedBorder.Content = EncryptedInnerGrid;
253
254 // Add borders to the status grid
255 StatusGrid.Children.Add(TransientBorder);
256 StatusGrid.Children.Add(EncryptedBorder);
257
258 // Set the Content of the ContentView to the constructed grid
259 this.Content = StatusGrid;
260 }
261 }
262}
A strongly-typed resource class, for looking up localized strings, etc.
static string Transient
Looks up a localized string similar to Transient.
static string Encrypted
Looks up a localized string similar to Encrypted.
Base class that references services in the app.
Definition: ServiceRef.cs:43
static IReportingStringLocalizer Localizer
Localization service
Definition: ServiceRef.cs:370
Static class that gives access to app-specific styles
Definition: AppStyles.cs:12
A custom control that indicates parameter protection status using transient and encrypted indicators.
static readonly BindableProperty EncryptedTextProperty
Bindable property for the encrypted text.
bool IsTransient
Gets or sets a value indicating whether the transient status is visible.
static readonly BindableProperty TransientTextProperty
Bindable property for the transient text.
static readonly BindableProperty IsTransientProperty
Bindable property for controlling the visibility of the transient status indicator.
ParameterProtectionIndicator()
Initializes a new instance of the ParameterProtectionIndicator class.
bool IsEncrypted
Gets or sets a value indicating whether the encrypted status is visible.
static readonly BindableProperty IsEncryptedProperty
Bindable property for controlling the visibility of the encrypted status indicator.