[英]How To Bind Array Of Images In c# To XAML Image Source?
我使用XAMLDirect3D开发windows phone 8游戏应用程序。
我需要存储数组中的图像列表。 在每个按钮上单击图像必须更改。 这是我的要求。
我尝试使用以下代码在图像中存储图像的imageBrush并将数组img传递给Xaml它工作正常。我尝试相同的图像代码,但它不起作用。
请告诉我这是正确的方式或我的要求的任何其他方式。
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]);
这可能会对你有所帮助。
imgBackground.ImageSource = new BitmapImage(new Uri("Images/" + imgChange[bgImgIndex], UriKind.Relative))
or
imgBackground.Source= new BitmapImage(new Uri("Images/" + imgChange[bgImgIndex], UriKind.Relative))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.