Skip to content

QueryProperty not set for ShellItem pages #11113

@ckrutsinger

Description

@ckrutsinger

Description

QueryProperty is not set when invoking a route to a ShellContent page that replaces the navigation stack (i.e. begins with //):

var route = $"//{nameof(LoginPage)}"; // <---- route as root page of navigation stack var query = new Dictionary<string, object>() { [LoginPage.InitiateAutomaticallyParam] = "true" }; Shell.Current.GoToAsync(route, query);

Here is the AppShell.xaml:

`

<ShellItem Route="MainPage">
    <ShellContent 
        Title="Title"
        ContentTemplate="{DataTemplate local:MainPage}"
        />
</ShellItem>

//  ...

<ShellItem Route="LoginPage" >
    <ShellContent 
        Title="{x:Static localize:Lang.Login}"
        ContentTemplate="{DataTemplate local:LoginPage}"
        FlyoutItemIsVisible="False"
        />
</ShellItem>
`

Here is the code behind for LoginPage.xaml.cs:

`
[QueryProperty(nameof(InitiateAutomatically), nameof(InitiateAutomatically))]
public partial class LoginPage : ContentPage/, IQueryAttributable/
{
private string _initiateAutomatically;

public string InitiateAutomatically
{
	get { return _initiateAutomatically; }
	set { _initiateAutomatically = value; }
}

public static string InitiateAutomaticallyParam = nameof(InitiateAutomatically);

public LoginPage(LoginPageViewModel viewModel)
{
	InitializeComponent();

	BindingContext = viewModel;
}

protected override void OnAppearing()
{
	base.OnAppearing();
	bool.TryParse(InitiateAutomatically, out var initiateAutomatically); //   <--------- InitiateAutomatically is null
	if (initiateAutomatically)
	{
		Console.WriteLine("got here"); //          <-------------------------never gets here
	}
}

}
`

If I navigate without //, then the QueryProperty is set as expected. For example:

{ var route = $"{nameof(LoginPage)}"; // <------------- route without // var query = new Dictionary<string, object>() { [LoginPage.InitiateAutomaticallyParam] = "true" }; Shell.Current.GoToAsync(route, query);

Steps to Reproduce

  1. Download the sample app
  2. Run (I tested on Android 11 and on Windows 11)
  3. Tap "Navigate to Second Page" button and check console output. Will say "QueryParam = push". This is correct.
  4. Tap "Navigate to Second Page as Root" button and check console output. Will say "QueryParam = not populated" because the passed value of the param ("root") did not populate the QueryParam property.

To create this in a new app:

  1. create a MAUI app
  2. add a second ContentPage
  3. add page to AppShell.xaml as a page
  4. add a property and a QueryProperty attribute to the new page
  5. navigation to page with // at beginning of route and include a property value in the route (e.g. //PageName?SomeProp=true)

The property will not populate.

If you remove the //, the property will populate.

Link to public reproduction project repository

https://github.com/ksoftllc/MauiQueryPropertyBug.git

Version with bug

6.0.486 (current)

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android 11, Windows 11

Did you find any workaround?

Yes. Even though the property does not get set, ApplyQueryAttributes does get called if IQueryAttributable is implemented.

Relevant log output

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-controls-shellShell Navigation, Routes, Tabs, Flyoutarea-navigationNavigationPagepartner/syncfusionIssues / PR's with Syncfusion collaborationplatform/androids/triagedIssue has been revieweds/verifiedVerified / Reproducible Issue ready for Engineering Triaget/bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions