-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
NavigableElement.cs
121 lines (106 loc) · 4.45 KB
/
NavigableElement.cs
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
111
112
113
114
115
116
117
118
119
120
121
#nullable disable
using System.Collections.Generic;
using System.ComponentModel;
using Microsoft.Maui.Controls.Internals;
using Microsoft.Maui.Controls.StyleSheets;
namespace Microsoft.Maui.Controls
{
/// <summary>Represents an <see cref="Element"/> with base functionality for <see cref="Page"/> navigation. Does not necessarily render on screen.</summary>
/// <remarks>Not meant to be used directly. Instead, opt to use derived types, such as <see cref="View"/>.</remarks>
public class NavigableElement : Element, INavigationProxy, IStyleSelectable
{
static readonly BindablePropertyKey NavigationPropertyKey =
BindableProperty.CreateReadOnly(nameof(Navigation), typeof(INavigation), typeof(VisualElement), default(INavigation));
/// <summary>Bindable property for <see cref="Navigation"/>.</summary>
public static readonly BindableProperty NavigationProperty = NavigationPropertyKey.BindableProperty;
/// <summary>Bindable property for <see cref="Style"/>.</summary>
public static readonly BindableProperty StyleProperty =
BindableProperty.Create(nameof(Style), typeof(Style), typeof(VisualElement), default(Style),
propertyChanged: (bindable, oldvalue, newvalue) => ((NavigableElement)bindable)._mergedStyle.Style = (Style)newvalue);
internal readonly MergedStyle _mergedStyle;
internal NavigableElement()
{
Navigation = new NavigationProxy();
_mergedStyle = new MergedStyle(GetType(), this);
}
/// <summary>Gets the object responsible for handling stack-based navigation.</summary>
/// <remarks>Binds to the <see cref="NavigationProperty"/> <see cref="BindableProperty"/>.</remarks>
public INavigation Navigation
{
get { return (INavigation)GetValue(NavigationProperty); }
internal set { SetValue(NavigationPropertyKey, value); }
}
/// <summary>Gets or sets the unique <see cref="Style"/> for this element.</summary>
public Style Style
{
get { return (Style)GetValue(StyleProperty); }
set { SetValue(StyleProperty, value); }
}
/// <summary>Gets or sets the style classes for the element.</summary>
/// <remarks>
/// <para>Equiavalent to <see cref="@class"/>.</para>
/// <para>Style classes enable multiple styles to be applied to a control, without resorting to style inheritance.</para>
/// </remarks>
/// <seealso href="https://learn.microsoft.com/dotnet/maui/user-interface/styles/xaml?view=net-maui-8.0#style-classes">Conceptual documentation on style classes</seealso>
[System.ComponentModel.TypeConverter(typeof(ListStringTypeConverter))]
public IList<string> StyleClass
{
get { return @class; }
set { @class = value; }
}
/// <summary>Gets or sets the style classes for the element.</summary>
/// <remarks>
/// <para>Equiavalent to <see cref="StyleClass"/>.</para>
/// <para>Style classes enable multiple styles to be applied to a control, without resorting to style inheritance.</para>
/// </remarks>
/// <seealso href="https://learn.microsoft.com/dotnet/maui/user-interface/styles/xaml?view=net-maui-8.0#style-classes">Conceptual documentation on style classes</seealso>
[System.ComponentModel.TypeConverter(typeof(ListStringTypeConverter))]
public IList<string> @class
{
get { return _mergedStyle.StyleClass; }
set
{
_mergedStyle.StyleClass = value;
}
}
IList<string> IStyleSelectable.Classes => StyleClass;
/// <summary>Gets the cast of <see cref="Navigation"/> to a <see cref="Maui.Controls.Internals.NavigationProxy"/>.</summary>
/// <remarks>
/// <para>Determines whether the element will proxy navigation calls.</para>
/// <para>For internal use by .NET MAUI.</para>
/// </remarks>
[EditorBrowsable(EditorBrowsableState.Never)]
public NavigationProxy NavigationProxy
{
get { return Navigation as NavigationProxy; }
}
/// <summary>Raises the (internal) <c>ParentSet</c> event.</summary>
/// <remarks>
/// Will set the <see cref="NavigationProxy">NavigationProxy's</see> inner navigation object to closest topmost element capable of handling navigation calls.
/// </remarks>
/// <seealso cref="Element.OnParentSet"/>
protected override void OnParentSet()
{
base.OnParentSet();
Element parent = Parent;
INavigationProxy navProxy = null;
while (parent != null)
{
if (parent is INavigationProxy proxy)
{
navProxy = proxy;
break;
}
parent = parent.RealParent;
}
if (navProxy != null)
{
NavigationProxy.Inner = navProxy.NavigationProxy;
}
else
{
NavigationProxy.Inner = null;
}
}
}
}