2011-11-26 106 views
0

我試圖通過photochoosertask插入圖像中的按鈕添加背景圖片使用PhotoChooserTask

一個按鈕,但在鑄造btnSelectImage.Content如圖片它給空

可以請你幫我出

void photoChooserTask_Completed(object sender, Microsoft.Phone.Tasks.PhotoResult e) 
    { 
     if (e.TaskResult == TaskResult.OK) 
     { 
      Image contentImage = btnSelectImage.Content as Image; 
      if (contentImage != null) 
      { 
       contentImage.Source = new System.Windows.Media.Imaging.BitmapImage(new Uri(e.OriginalFileName)); 
      } 
     } 
    } 

回答

0
void photoChooserTask_Completed(object sender, Microsoft.Phone.Tasks.PhotoResult e) 
    { 
     if (e.TaskResult == TaskResult.OK) 
     { 
      BitmapImage bitmap = new BitmapImage(); 
      bitmap.SetSource(e.ChosenPhoto); 
      contentImage.Source = bitmap; 
     } 
    } 

試試這個。

我不確定你xaml的樣子。你必須使用這種方式

<Button> 
    <Image x:Name="contentImage" /> 
</Button> 
+0

問題是 - contentImage即將空 – 1Mayur

+0

你能發表您的XAML的位置>另外,看看我的編輯幫助 – abhinav

+0

<按鈕內容=「選擇圖片」 HEIGHT =「200 「Margin =」12,6,0,0「Name =」btnSelectImage「VerticalAlignment =」Top「Horizo​​ntalAlignment =」Left「Width =」200「Click =」btnSelectImage_Click「Background =」Transparent「Grid.ColumnSpan =」2「Grid .RowSpan =「3」不透明度=「1」/> – 1Mayur