2011-11-26 87 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