-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathContentView.cs
More file actions
110 lines (93 loc) · 3.75 KB
/
Copy pathContentView.cs
File metadata and controls
110 lines (93 loc) · 3.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#nullable disable
using System.Diagnostics;
using Microsoft.Maui;
using Microsoft.Maui.Graphics;
using Microsoft.Maui.Layouts;
namespace Microsoft.Maui.Controls
{
/// <summary>
/// An element that contains a single child element.
/// </summary>
/// <remarks>
/// ContentView is a simple container that hosts a single <see cref="View"/> element through its <see cref="Content"/> property.
/// It is commonly used as a base class for custom views or to apply templates to content.
/// </remarks>
[ContentProperty("Content")]
[DebuggerDisplay("{GetDebuggerDisplay(), nq}")]
public partial class ContentView : TemplatedView, IContentView, ISafeAreaView2, ISafeAreaElement
{
/// <summary>Bindable property for <see cref="Content"/>.</summary>
public static readonly BindableProperty ContentProperty = BindableProperty.Create(nameof(Content), typeof(View), typeof(ContentView), null, propertyChanged: TemplateUtilities.OnContentChanged);
/// <summary>
/// Gets or sets the content of the ContentView. This is a bindable property.
/// </summary>
/// <value>A <see cref="View"/> that contains the content.</value>
public View Content
{
get { return (View)GetValue(ContentProperty); }
set { SetValue(ContentProperty, value); }
}
/// <summary>Bindable property for <see cref="SafeAreaEdges"/>.</summary>
public static readonly BindableProperty SafeAreaEdgesProperty = SafeAreaElement.SafeAreaEdgesProperty;
/// <summary>
/// Gets or sets the safe area edges to obey for this content view.
/// The default value is SafeAreaEdges.None (edge-to-edge).
/// </summary>
/// <remarks>
/// This property controls which edges of the content view should obey safe area insets.
/// Use SafeAreaRegions.None for edge-to-edge content, SafeAreaRegions.All to obey all safe area insets,
/// SafeAreaRegions.Container for content that flows under keyboard but stays out of bars/notch, or SafeAreaRegions.SoftInput for keyboard-aware behavior.
/// </remarks>
public SafeAreaEdges SafeAreaEdges
{
get => (SafeAreaEdges)GetValue(SafeAreaElement.SafeAreaEdgesProperty);
set => SetValue(SafeAreaElement.SafeAreaEdgesProperty, value);
}
protected override void OnBindingContextChanged()
{
base.OnBindingContextChanged();
if (Content is View content)
{
SetInheritedBindingContext(content, BindingContext);
}
}
internal override void OnControlTemplateChanged(ControlTemplate oldValue, ControlTemplate newValue)
{
base.OnControlTemplateChanged(oldValue, newValue);
if (Content is View content)
{
SetInheritedBindingContext(content, BindingContext);
}
}
internal override void SetChildInheritedBindingContext(Element child, object context)
{
SetInheritedBindingContext(child, context);
}
object IContentView.Content => Content;
IView IContentView.PresentedContent => ((this as IControlTemplated).TemplateRoot as IView) ?? Content;
SafeAreaEdges ISafeAreaElement.GetDefaultSafeAreaEdges()
{
return SafeAreaEdges.None;
}
private protected override string GetDebuggerDisplay()
{
var contentText = DebuggerDisplayHelpers.GetDebugText(nameof(Content), Content);
return $"{base.GetDebuggerDisplay()}, {contentText}";
}
/// <inheritdoc cref="ISafeAreaView2.HasExplicitSafeAreaEdges"/>
bool ISafeAreaView2.HasExplicitSafeAreaEdges => SafeAreaElement.IsSafeAreaEdgesSet(this);
/// <inheritdoc cref="ISafeAreaView2.GetSafeAreaRegionsForEdge"/>
SafeAreaRegions ISafeAreaView2.GetSafeAreaRegionsForEdge(int edge)
{
// Use direct property
var regionForEdge = SafeAreaEdges.GetEdge(edge);
if (regionForEdge == SafeAreaRegions.Default)
{
// If no safe area edges are set, return None
return SafeAreaRegions.None;
}
// For ContentView, return the region directly
return regionForEdge;
}
}
}