[QueryProperty("SomeQueryParameter", "SomeQueryParameter")]
public class ShellTestPage : ContentPage
{
- public string SomeQueryParameter { get; set; }
+ public string SomeQueryParameter
+ {
+ get;
+ set;
+ }
}
protected ShellItem CreateShellItem(TemplatedPage page = null, bool asImplicit = false, string shellContentRoute = null, string shellSectionRoute = null, string shellItemRoute = null)
[Test]
+ public async Task NavigationWithQueryStringThenWithoutQueryString()
+ {
+ var shell = new Shell();
+
+ var one = new ShellItem { Route = "one" };
+ var two = new ShellItem { Route = "two" };
+
+ var tabone = MakeSimpleShellSection("tabone", "content");
+ var tabfour = MakeSimpleShellSection("tabfour", "content", null);
+
+ one.Items.Add(tabone);
+ two.Items.Add(tabfour);
+
+ shell.Items.Add(one);
+ shell.Items.Add(two);
+
+ ShellTestPage pagetoTest = new ShellTestPage();
+ await shell.GoToAsync(new ShellNavigationState($"//two/tabfour/content?{nameof(ShellTestPage.SomeQueryParameter)}=1234"));
+ two.CurrentItem.CurrentItem.ContentTemplate = new DataTemplate(() =>
+ {
+ pagetoTest = new ShellTestPage();
+ pagetoTest.BindingContext = pagetoTest;
+ return pagetoTest;
+ });
+
+
+ await shell.GoToAsync(new ShellNavigationState($"//one/tabone/content"));
+ await shell.GoToAsync(new ShellNavigationState($"//two/tabfour/content"));
+
+ var page = (two.CurrentItem.CurrentItem as IShellContentController).GetOrCreateContent();
+ Assert.AreEqual(null, (page as ShellTestPage).SomeQueryParameter);
+ }
+
+
+ [Test]
+ public async Task NavigationBetweenShellContentsPassesQueryString()
+ {
+ var shell = new Shell();
+
+ var item = CreateShellItem(shellSectionRoute: "section2");
+ var content = CreateShellContent(shellContentRoute: "content");
+ item.Items[0].Items.Add(content);
+
+ Routing.RegisterRoute("details", typeof(ShellTestPage));
+
+ shell.Items.Add(item);
+
+
+ await shell.GoToAsync(new ShellNavigationState($"//section2/details?{nameof(ShellTestPage.SomeQueryParameter)}=1234"));
+ await shell.GoToAsync(new ShellNavigationState($"//content?{nameof(ShellTestPage.SomeQueryParameter)}=1234"));
+ await shell.GoToAsync(new ShellNavigationState($"//section2/details?{nameof(ShellTestPage.SomeQueryParameter)}=4321"));
+
+ var testPage = (shell.CurrentItem.CurrentItem as IShellSectionController).PresentedPage as ShellTestPage;
+ Assert.AreEqual("4321", testPage.SomeQueryParameter);
+ }
+
+
+ [Test]
public async Task NavigationWithQueryStringAndNoDataTemplate()
{
var shell = new Shell();
await shell.GoToAsync(new ShellNavigationState($"//two/tabfour/content?{nameof(ShellTestPage.SomeQueryParameter)}=1234"));
Assert.AreEqual("1234", (two.CurrentItem.CurrentItem.Content as ShellTestPage).SomeQueryParameter);
-
}
[Test]
internal static void ApplyQueryAttributes(Element element, IDictionary<string, string> query, bool isLastItem)
{
- if (query.Count == 0)
- return;
-
string prefix = "";
if (!isLastItem)
{
filteredQuery.Add(key, q.Value);
}
- if (baseShellItem != null)
+ if (baseShellItem is ShellContent)
baseShellItem.ApplyQueryAttributes(filteredQuery);
else if (isLastItem)
element.SetValue(ShellContent.QueryAttributesProperty, query);