C# 表单Shell如何注入多个不同的值;在路线导航中使用字符串
如何将任何属性注入到我们使用Xamarin本机导航的页面中?这很简单,因为您必须实例化页面的类型:C# 表单Shell如何注入多个不同的值;在路线导航中使用字符串,c#,xamarin.forms,xamarin.forms.shell,C#,Xamarin.forms,Xamarin.forms.shell,如何将任何属性注入到我们使用Xamarin本机导航的页面中?这很简单,因为您必须实例化页面的类型: Navigation.PushAsync(new HomeViewPage { x = y }); 在Shell中,只允许传递字符串值 Shell.Current.GoToAsync($"//home/bottomtab2?name={"Cat"}"); 我试图传递一个布尔值,结果显示以下错误: 无法将“System.String”类型的“Object of type”转换为“System.B
Navigation.PushAsync(new HomeViewPage { x = y });
在Shell中,只允许传递字符串值
Shell.Current.GoToAsync($"//home/bottomtab2?name={"Cat"}");
我试图传递一个布尔值,结果显示以下错误:
无法将“System.String”类型的“Object of type”转换为“System.Boolean”类型。
Shell.Current.GoToAsync($"//home/bottomtab2?test={true}");
如果您尝试发送多个参数,则所有发送的参数都不起作用,是否有方法同时发送多个参数
Shell.Current.GoToAsync($"//home/bottomtab2?name={"Cat"}?test={"Dog"}");
首先,当您在路由uri中传递值时,需要将多个参数连接到
&
而不是?
等
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;
}
}
您链接的页面上有@Jason的信息,但它只允许我传递字符串值,我正在尝试传递布尔值,它显示以下错误:“类型的对象”System.string“无法转换为类型”System.Boolean“。谢谢!Uri.UnescapeDataString就是我想要的删除那些讨厌的%22!