Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
SafeInsetsExtension.cs
1using Microsoft.Maui.Controls;
2using Microsoft.Maui.Controls.Xaml;
4using System;
5using System.Linq;
6
8{
9 public enum InsetsType
10 {
11 Top,
12 Bottom,
13 TopAndBottom,
14 Right,
15 Left,
16 RightAndLeft,
17 All
18 }
19
20 [AcceptEmptyServiceProvider]
21 [ContentProperty(nameof(Type))]
22 public class SafeInsetsExtension : IMarkupExtension
23 {
24 public InsetsType Type { get; set; } = InsetsType.TopAndBottom;
25
26 public object ProvideValue(IServiceProvider serviceProvider)
27 {
28 Thickness Insets = ServiceRef.PlatformSpecific.GetInsets();
29
30
31 return this.Type switch
32 {
33 InsetsType.Top => new Thickness(0, Insets.Top, 0, 0),
34 InsetsType.Bottom => new Thickness(0, 0, 0, Insets.Bottom),
35 InsetsType.TopAndBottom => new Thickness(0, Insets.Top, 0, Insets.Bottom),
36 InsetsType.Right => new Thickness(0, 0, Insets.Right, 0),
37 InsetsType.Left => new Thickness(Insets.Left, 0, 0, 0),
38 InsetsType.RightAndLeft => new Thickness(Insets.Left, 0, Insets.Right, 0),
39 InsetsType.All => new Thickness(Insets.Left, Insets.Top, Insets.Right, Insets.Bottom),
40 _ => new Thickness(0)
41 };
42 }
43 }
44}
Base class that references services in the app.
Definition: ServiceRef.cs:43
static IPlatformSpecific PlatformSpecific
Localization service
Definition: ServiceRef.cs:383
Thickness GetInsets()
Gets the safe area insets for the device (top, bottom, left, right).
Definition: ImplTypes.g.cs:58