public static void ApplyQueryAttributes(Element element, ShellRouteParameters query, bool isLastItem, bool isPopping) { string prefix = ""; if (!isLastItem) { var route = Routing.GetRoute(element); if (string.IsNullOrEmpty(route) || Routing.IsImplicit(route)) { return; } prefix = route + "."; } //if the lastItem is implicitly wrapped, get the actual ShellContent if (isLastItem) { if (element is IShellItemController shellitem && shellitem.GetItems().FirstOrDefault() is ShellSection section) { element = section; } if (element is IShellSectionController shellsection && shellsection.GetItems().FirstOrDefault() is ShellContent content) { element = content; } if (element is ShellContent shellcontent && shellcontent.Content is Element e) { element = e; } } if (!(element is BaseShellItem baseShellItem)) { baseShellItem = element?.Parent as BaseShellItem; } //filter the query to only apply the keys with matching prefix var filteredQuery = new ShellRouteParameters(query.Count); foreach (var q in query) { if (!q.Key.StartsWith(prefix, StringComparison.Ordinal)) { continue; } var key = q.Key.Substring(prefix.Length); if (key.IndexOf(".", StringComparison.Ordinal) != -1) { continue; } filteredQuery.Add(key, q.Value); } if (baseShellItem is ShellContent) { baseShellItem.ApplyQueryAttributes(MergeData(element, filteredQuery, isPopping)); } else if (isLastItem) { element.SetValue(ShellContent.QueryAttributesProperty, MergeData(element, query, isPopping)); } ShellRouteParameters MergeData(Element shellElement, ShellRouteParameters data, bool isPopping) { if (!isPopping) { return(data); } var returnValue = new ShellRouteParameters(data); var existing = (ShellRouteParameters)shellElement.GetValue(ShellContent.QueryAttributesProperty); if (existing == null) { return(data); } foreach (var datum in existing) { if (!returnValue.ContainsKey(datum.Key)) { returnValue[datum.Key] = datum.Value; } } return(returnValue); } }
/// <include file="../../docs/Microsoft.Maui.Controls/Routing.xml" path="//Member[@MemberName='SetRoute']/Docs" /> public static void SetRoute(Element obj, string value) { obj.SetValue(RouteProperty, value); }