我无法将图像显示到另一页。图片取自json。所以我试图将列表框的选定项目的图像 url 传递到导航查询字符串中。我试图传递数据的变量显示为 null。请为我提供解决方案。谢谢
这里是第一页的代码:
private void ImageList_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var lbi = (sender as ListBox).SelectedItem;
if (e.AddedItems.Count > 0)
{
Uri targetPage = new Uri("/DisplayPhoto.xaml?selectedItem="+ lbi.ToString(),UriKind.RelativeOrAbsolute);
NavigationService.Navigate(targetPage);
}
((ListBox)sender).SelectedIndex = -1;
}
第二页代码:
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
string selectedIndex = "";
if (NavigationContext.QueryString.TryGetValue("selectedItem", out selectedIndex))
{
Uri uri = new Uri(selectedIndex, UriKind.Absolute);
var img = new Image();
img.Source = new BitmapImage(uri);
img.Height = 400;
img.Width = 400;
listBox1.Items.Add(img);
}
base.OnNavigatedTo(e);
}