2012-05-21 22 views
1

我试图在运行时更改图像的来源,以便在点击后更改图像。到目前为止,我在下面的代码似乎导致图像变成空白。Windows Mobile 7 - C#在运行时更改图像源

BitmapImage imgSource = 
      new BitmapImage(new Uri("/PivotApp1;component/Images/halfstar.png")); 
image1.Source = imgSource; 

在运行时是否需要做某些特殊的事情来改变资源映像?然而,我试图通过谷歌搜索,到目前为止,每个类似的情况导致了一个空白的图像。我认为也许源uri是错误的,但我认为这不是原因,因为这是默认图像加载时的uri。

回答

3

告诉URI是相对

BitmapImage imgSource = new BitmapImage(
      new Uri("/PivotApp1;component/Images/halfstar.png", UriKind.Relative)); 

分配您的ImageSource

image1.Source = null; 
image1.Source = imgSource; 
+1

谢谢,这工作之前尝试设置源为空。我想它需要把UriKind.Relative扔进去。 – Euthyphro

+0

感谢你。很高兴我能帮助你。 –