下载解析xml 内有图片路径和给定的一个id
XElement root = XElement.Parse(e.Result);
var q = from mi in root.Elements("ImageNameItem")
select new
{
Left = double.Parse(mi.Attribute("Left").Value),
Top = double.Parse(mi.Attribute("Top").Value),
Angle = int.Parse(mi.Attribute("Angle").Value),
Image = mi.Attribute("Image").Value,
RollImage = mi.Attribute("RollImage").Value,
ID=int.Parse(mi.Attribute("ID").Value),
TrueUri=mi.Attribute("TrueUri").Value
};
int duration = int.Parse(root.Attribute("Duration").Value) / 2;
foreach (var item in q)
{ ImageNewsNameView//图片显示控件
ImageNewsNameView innv = new ImageNewsNameView(duration, item.Image, item.RollImage);
var img = innv;
img.Angle = item.Angle;
img.Opacity = 0.3;
//赋值新uri id 只赋值了最后一次!!!。。。。
innv.txtID.Items.Add(item.ID.ToString());
innv.txtUri.Items.Add(item.TrueUri);
innv.image.MouseLeftButtonDown += new MouseButtonEventHandler(image_MouseLeftButtonDown);
myImageNewsNameView.Children.Add(img);
Canvas.SetLeft(img, item.Left);
Canvas.SetTop(img, item.Top);
}
void image_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (clear)
{
if (int.Parse(innv.txtID.Items[0].ToString()) == 0)
{ImageNewsView 点击图片显示较大图片空间
ImageNewsView inv = new ImageNewsView(innv.txtUri.Items[0].ToString());
this.myImageNewsView.Children.Add(inv);
clear = false;
}
就是想问下。。foreach 循环为什么只赋值了最后一次??