2014-03-13 56 views
3

我使用XAMLDirect3D开发windows phone 8游戏应用程序。如何将c#中的图像数组绑定到XAML图像源?

我需要存储数组中的图像列表。在每个按钮上单击图像必须更改。这是我的要求。

我尝试imageBrush与下面的代码存储图像在数组和传递数组img到Xaml它工作正常。我尝试相同的代码的图像,但它不工作。

PLZ告诉它正确的方式或任何其他方式存在我的要求。

XAML:

<Grid.Background> 
     <ImageBrush x:Name="imgBackground" Stretch="Fill"></ImageBrush> 
    </Grid.Background> 

C#:

string[] imgChange; 

imgChange = new string[4]; 
imgChange[0] = "bg1.png"; 
imgChange[1] = "bg2.png"; 
imgChange[2] = "bg3.png"; 
imgChange[3] = "bg4.png"; 

imgBackground.ImageSource = (ImageSource)new ImageSourceConverter().ConvertFromString("Images/" + imgChange[bgImgIndex]); 

回答

3

可能这会帮助你。

imgBackground.ImageSource = new BitmapImage(new Uri("Images/" + imgChange[bgImgIndex], UriKind.Relative)) 

          or 
imgBackground.Source= new BitmapImage(new Uri("Images/" + imgChange[bgImgIndex], UriKind.Relative)) 
+0

它工作正常。 – Gurunathan

相关问题