C#WPF中for周期中的Se图像源 [英] Se Image Source in a for Cycle in C# WPF

查看:81
本文介绍了C#WPF中for周期中的Se图像源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在WPF 40图像的窗口中有一个图像,对于此图像中的每个图像,我都需要在运行时以编程方式设置图像源...

我可以做For Cicle吗?如何 ?

例如我有:
图片1
图片2
图片3
图片4

对于带有周期的设置图像我该怎么办?

for(int i = 1; i< ???????; i ++){
图像???? .Source = new BitmapImage(new Uri("pack://application:,,,/{AssemblyName}; component/Images/MyImage.png");
}


问号是用于说明我不知道该怎么做的指示符:D

在此先感谢您的帮助.

I have in a Window in WPF 40 image, for each of this image i need to set an image source at runtime programatically ...

Can i do a For cicle ? How ?

For example i have :
Image1
Image2
Image3
Image4

For Set image with a cycle for how can i do ?

for(int i = 1;i < ???????;i++) {
Image???? .Source = new BitmapImage(new Uri("pack://application:,,,/{AssemblyName};component/Images/MyImage.png");
}


The Question marks are indicative for explain what i don''t know how to :D

Thanks in advancefor any kind of help.

推荐答案

使用FindName 如图所示
Use FindName as shown here.

for(int i = 1;i < 40;i++) {
StackPanel sp = dt.FindName("OuterPanel",cp) as StackPanel;
//cp is the ContentPresenter
Image img = sp.FindName("Image" + i) as Image;
img.Source = new BitmapImage(new Uri("pack://application:,,,/{AssemblyName};component/Images/MyImage.png");
}


根据我的例子,您能做一个实际的例子吗? :D

谢谢.
Can you do a pratical example , based on my example ? :D

Thanks .


这篇关于C#WPF中for周期中的Se图像源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆