How to pass the image value in one xaml page to an

2019-01-15 12:31发布

问题:

My Requirement is, in first xaml page place all the images .if whenever click on particular image that image can be displayed in another xaml page .How To pass The image value from one xaml page to another xaml page for windows phone 7 app developement using silverlight.

回答1:

There's a good screencast on different ways of navigating between pages (and passing values) from DimeCasts.net at http://www.dimecasts.net/Casts/CastDetails/174

As an example of one way of doing this (and assuming the images were in a ListBox) would be to add the following to the SelectionChanged event.

private void OnSelectedImageChanged(object sender, SelectionChangedEventArgs e)
{
  NavigationService.Navigate(new Uri(string.Format("/image/{0}", HttpUtility.UrlEncode(((sender as ListBox).SelectedItem as PhotoViewModel).uri)), UriKind.Relative));
}

The above assumes an appropriately mapped route like:

<nav:UriMapping Uri="/image/{image}" MappedUri="/Image.xaml?u={image}" />

and that the original listbox was bound to the uri property of a PhotoViewModel object.

Hopefully, watching the screencast should make any of the above clearer.