4

如何将任何属性注入到我们使用Shell导航的页面中 使用Xamarin 的本机导航很简单,因为您必须实例化页面的类型:

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

在 Shell 中只允许我传递字符串值

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

我正在尝试传递一个布尔值,它向我显示以下错误: “'System.String' 类型的对象无法转换为'System.Boolean' 类型。”

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

如果你尝试发送多个参数,发送的参数都不起作用,有没有办法同时发送几个?

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

1 回答 1

3

首先当你在Route uri中传递值时,需要连接多个参数而&不是?like

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

第二,如果你想传递一个bool类型

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

在您的目标页面中,您可以将其作为字符串接收,然后它不会抛出错误,例如:

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

    }
}
于 2019-10-25T03:12:21.303 回答