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
- Download the sample app
- Run (I tested on Android 11 and on Windows 11)
- Tap "Navigate to Second Page" button and check console output. Will say "QueryParam = push". This is correct.
- 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:
- create a MAUI app
- add a second ContentPage
- add page to AppShell.xaml as a page
- add a property and a QueryProperty attribute to the new page
- 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
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:
`
Here is the code behind for LoginPage.xaml.cs:
`
[QueryProperty(nameof(InitiateAutomatically), nameof(InitiateAutomatically))]
public partial class LoginPage : ContentPage/, IQueryAttributable/
{
private string _initiateAutomatically;
}
`
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
To create this in a new app:
//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,
ApplyQueryAttributesdoes get called ifIQueryAttributableis implemented.Relevant log output
No response