public static void SetRoute(Element obj, string value) { obj.SetValue(RouteProperty, value); }
public static void ApplyQueryAttributes(Element element, IDictionary <string, string> 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 Dictionary <string, string>(query.Count); foreach (var q in query) { if (!q.Key.StartsWith(prefix, StringComparison.Ordinal)) { continue; } var key = q.Key.Substring(prefix.Length); if (key.Contains(".")) { 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)); } IDictionary <string, string> MergeData(Element shellElement, IDictionary <string, string> data, bool isPopping) { if (!isPopping) { return(data); } var returnValue = new Dictionary <string, string>(data); var existing = (IDictionary <string, string>)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); } }