单击列表视图图像,在C#(wp8.1)中使用相同的图像在下一个屏幕上显示详细信息

时间:2015-08-21 19:55:35

标签: c# listview windows-phone-8.1

我在windows phone 8.1应用程序中创建了带代码绑定的自定义列表视图。 Listview中有图像列表。

Images displaying in Listview

我的代码就在这里,

    public sealed partial class MainPage : Page
      {
    List<product> abc = new List<product>();
    public MainPage()
    {
        this.InitializeComponent();


        helloyouthere();


        //arsal is listview name.

        arsal.DataContext = abc;

        arsal.SelectionChanged += arsal_SelectionChanged;

        this.NavigationCacheMode = NavigationCacheMode.Required;
    }

    public void helloyouthere()
    {
        abc.Add(new product() { imagepath = "/Assets/21.png" });
        abc.Add(new product() { imagepath = "/Assets/22.png" });
        abc.Add(new product() { imagepath = "/Assets/23.png" });
        abc.Add(new product() { imagepath = "/Assets/24.png" });
        abc.Add(new product() { imagepath = "/Assets/25.png" });
        abc.Add(new product() { imagepath = "/Assets/26.png" });
        abc.Add(new product() { imagepath = "/Assets/27.png" });
        abc.Add(new product() { imagepath = "/Assets/28.png" });
        abc.Add(new product() { imagepath = "/Assets/29.png" });
        abc.Add(new product() { imagepath = "/Assets/30.png" });

    }

    private async void arsal_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {

            MessageDialog msgbox2 = new MessageDialog(arsal.SelectedIndex.ToString());
            await msgbox2.ShowAsync();
            this.Frame.Navigate(typeof(detail), arsal.SelectedIndex);
    }

我只是想点击这个,并希望在下一个屏幕上获得完整的图像,

    this.Frame.Navigate(typeof(detail), arsal.SelectedIndex);

我的详细信息页面在xaml文件中有一个图像控件, detail.cs页面代码在这里。

         public detail()
        {
        this.InitializeComponent();
        MainPage obj = new MainPage();

       // "imaged"  is my image Control

      // How to get Image here  
    }

我想在这里展示我的形象。

无法在此处获取图片。

我的关于页面Xaml代码在这里

   <Grid x:Name="maingrid">
    <Image x:Name="imaged" VerticalAlignment="Center" HorizontalAlignment="Center"
         Width="360" Height="360" Stretch="UniformToFill"   >

    </Image>


</Grid>

我没有在about.cs动态获取我的图像源。我给出了确切的代码,我在about.cs文件中尝试过特定的静态源,但每次imaged.source为NULL并显示异常。

1 个答案:

答案 0 :(得分:0)

你应该致电

this.Frame.Navigate(typeof(detail), ((product)arsal.SelectedItem).imagepath)

导航到您的详细信息页面。

然后在您的详细信息页面中,您可以使用OnNavigatedTo方法显示图片:

protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        var imagePath = e.Parameter as string;

        // Set to image control ImageSource
        imaged.Source = new BitmapImage(new Uri(imagePath, UriKind.RelativeOrAbsolute));
    }
相关问题