我设置了MasterDetail UI。左边是ListView。 ListView设置如下
public class MasterPageList
{
public string Text { get; set; }
public string Url { get; set; }
public override string ToString()
{
return Text;
}
}
var listOptions = new List<MasterPageList>
{
new MasterPageList{ Text = "Packt website", Url = "http://www.packt.com" },
new MasterPageList{ Text = "Farmtrack Live", Url = "http://www.farmapps.co.uk" },
new MasterPageList{ Text = "Henry Crunn", Url = "" }
};
// create the ListView - this is explained later in the book more fully in the What A Bind chapter
var listView = new ListView
{
ItemsSource = listOptions.ToArray()
};
// create the master page
Master = new ContentPage
{
Title = "Webviewer",
Content = new StackLayout
{
Children =
{
header, listView
}
}
};
ItemSelected事件会触发收件人页面
void LaunchPage(object s, SelectedItemChangedEventArgs e)
{
var binding = e.SelectedItem as MasterPageList;
var displayPage = new Page();
if (string.IsNullOrEmpty(binding.Url))
{
displayPage = (Page)Activator.CreateInstance(typeof(WebviewGenerated));
}
else
{
displayPage.BindingContext = e.SelectedItem;
displayPage = (Page)Activator.CreateInstance(typeof(Webview));
}
Detail = new NavigationPage(displayPage);
IsPresented = false;
}
当选择前两个ListItem中的任何一个时,将实例化接收ContentPage,但页面的BindingContext为null。我已经尝试了许多其他方法来从发送页面获取URL。
从我从其他例子中可以看到,我所做的是正确的,但结果显示不然。
在将网址传递到网页浏览页面时,我还需要做些什么吗?
答案 0 :(得分:0)
尝试以下方法:
var params = new Params {
url = "https://www.google.com",
querystring = ""
};
var secondPage = new SecondPage ();
secondPage.BindingContext = params;
await Navigation.PushAsync (secondPage);