MonoMatrix
MonoMatrix

Reputation: 123

Xamarin.Forms Shell how to inject multiple and different values ​to string in route navigation

How can any property be injected into a page that we navigate using Shell With Xamarin's native navigation it is simple since you have to instantiate the type of the page:

Navigation.PushAsync(new HomeViewPage { x = y });

In Shell only lets me pass string values

Shell.Current.GoToAsync($"//home/bottomtab2?name={"Cat"}");

I am trying to pass a Boolean value and it shows me the following error: 'Object of type 'System.String' cannot be converted to type 'System.Boolean'.'

Shell.Current.GoToAsync($"//home/bottomtab2?test={true}");

And if you tried to send several parameters, none of the sent parameters work, is there a way to send several simultaneously?

Shell.Current.GoToAsync($"//home/bottomtab2?name={"Cat"}?test={"Dog"}");

Upvotes: 4

Views: 3749

Answers (1)

Leo Zhu
Leo Zhu

Reputation: 14956

first when you pass the value in Route uri ,multiple parameters need to be connected with & not ? like

Shell.Current.GoToAsync($"//home/bottomtab2?name={"Cat"}&test={"Dog"}");

second if you want to pass a bool type

Shell.Current.GoToAsync($"//home/bottomtab2?test={true}");

in your target page,you could receive it as a string,then it won't throw error,like :

[QueryProperty("Test", "test")]
public partial class AboutPage : ContentPage
{
 string test;
 public string Test
    {
        set =>test = Uri.UnescapeDataString(value); 
        get => test;

    }
}

Upvotes: 4

Related Questions