WPF程序中怎么将ListString的值赋给Image的源
就是ListString里存了多个图片路径,现在要把这些路径逐个赋给Image组件的源,怎样写这里的代码...
就是ListString里存了多个图片路径,现在要把这些路径逐个赋给Image组件的源,怎样写这里的代码
展开
2个回答
展开全部
这很简单,假设你在前台有个StackPanel,里面放了三个Image控件。后台有一个List<string>存放了三张图片路径。
List<string> imgUrlList = new List<string>()
{
"Images/bz-head001.jpg",
"Images/bz-head002.jpg",
"Images/bz-head003.jpg"
};
for (int i = 0; i < sp_images.Children.Count; i++)
{
Image img = sp_images.Children[i] as Image;
img.Source = new BitmapImage(new Uri(imgUrlList[i], UriKind.Relative));
}
List<string> imgUrlList = new List<string>()
{
"Images/bz-head001.jpg",
"Images/bz-head002.jpg",
"Images/bz-head003.jpg"
};
for (int i = 0; i < sp_images.Children.Count; i++)
{
Image img = sp_images.Children[i] as Image;
img.Source = new BitmapImage(new Uri(imgUrlList[i], UriKind.Relative));
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询