Windows 8导航,将URI作为参数传递
本文关键字:参数传递 URI 导航 Windows | 更新日期: 2023-09-27 18:29:19
我刚开始为windows 8开发,在页面之间的导航中传递参数时遇到了一些困难。
我想做的是:我有两个页面(第1页和第2页)在第1页,有一个带按钮的菜单。当我点击这个按钮时,点击事件应该作为一个参数传递一个可能的URI或路径,它将设置page2中图像的源。
这是第1页的代码:
private void Button_Click_2(object sender, RoutedEventArgs e)
{
//this.Frame.Navigate(typeof(SplitPage), "ms-appx:/Imgs/1.png");
this.Frame.Navigate(typeof(SplitPage), new Uri("ms-appx:/Imgs/1.png", UriKind.RelativeOrAbsolute));
}
和页面2,用于接收Uri:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
var imgSource = e.Parameter as ImageSource;
this.imgParaPintar.Source = imgSource;
}
我注意到imgSource
什么也没收到,它保持为空。
那么,关于我做错了什么或我错过了什么,有什么线索吗?
我认为您需要这样的代码(未经测试):
protected override void OnNavigatedTo(NavigationEventArgs e)
{
this.imgParaPintar.Source = new BitmapImage((Uri)e.Parameter);
}
如果您还没有using Windows.UI.Xaml.Media.Imaging;
,您可能需要将其添加到文件中。
值得注意的是,正如这里的评论所述:
http://answers.flyppdevportal.com/categories/metro/csharpvb.aspx?ID=4b847d71-9cd5-4457-add9-f68e457b23ff
只能将基元类型作为导航参数传递。