2014-04-20 53 views
0

您好我想通過一個圖像作爲參數在Windows Phone應用程序。用戶可以單擊圖像的縮略圖,然後將其定向到具有該圖像的全尺寸副本的新頁面。傳遞圖像參數c#windows手機

我試過以下,但在「image.SetSource(e.OriginalSource);」下面出現紅線錯誤。下面?很顯然,手勢事件並不適合,但我不知道我還能使用什麼?

這是用戶點擊其中一個圖像時的事件代碼。該圖像被命名爲flickr1Image。

  private void flickr1Image_Tap(object sender, System.Windows.Input.GestureEventArgs e) 
    { 
     if (e.OriginalSource != null) 
     { 
     //Edits 
     if (PhoneApplicationService.Current.State.ContainsKey("Image")) 
       if (PhoneApplicationService.Current.State["Image"] != null) 
        PhoneApplicationService.Current.State.Remove("Image"); 
        System.Windows.Media.Imaging.BitmapImage image = new System.Windows.Media.Imaging.BitmapImage(); 
        image.SetSource(e.OriginalSource); 
        this.flickr1Image.Source = image; 
        PhoneApplicationService.Current.State["Image"] = image; 
     } 
    } 

下面是執行加載圖像到頁面的代碼。我希望下面的代碼能夠傳遞給它的所有圖像?

  protected override void OnNavigatedTo(NavigationEventArgs e) 
    { 
     BitmapImage image = new System.Windows.Media.Imaging.BitmapImage(); 
     image = (BitmapImage)PhoneApplicationService.Current.State["Image"]; 
     PhoneApplicationService.Current.State.Remove("Image"); 
     this.flick.Source = image; 
    } 

請幫助

千恩萬謝

+0

你的發件人是形象。將發件人轉換爲圖像並將BitmpaImage Source設置爲發件人源。 – Jaihind

回答

0

以爲我會分享以上的情況下,任何人都需要它我解決問題的方法...

添加有如下的靜態方法的類:

 class ImageStore 
    { 
     private static ImageStore current = new ImageStore(); 

     public static ImageStore Current 
     { 
      get { return current; } 
     } 

    public BitmapImage Image { get; set; } 

    } 

然後將此事件添加到事件中:

private void flickr1Image_Tap(object sender, System.Windows.Input.GestureEventArgs e) 
    { 
     ImageStore.Current.Image = (BitmapImage)flickr1Image.Source; 
     NavigationService.Navigate(new Uri("/flickrPage.xaml", UriKind.Relative)); 
    } 

然後這個rec​​ieving頁:

protected override void OnNavigatedTo(NavigationEventArgs e) 
    { 
     flick.Source = ImageStore.Current.Image; 
    } 

的圖像可以在任何地方進行檢索,每當我需要它..

...簡單