Display image using xml

thrallz

New Member
I am trying to make simple task that display all image using xml. But i can't that task completely. Please help me...

My xaml code:\[code\]<ScrollViewer> <ListBox x:Name="imglist" Loaded="imglist_Loaded"> <ListBox.ItemsPanel> <ItemsPanelTemplate> <toolkit:WrapPanel /> </ItemsPanelTemplate> </ListBox.ItemsPanel> <ListBox.ItemTemplate> <DataTemplate> <Image x:Name="img" Source="{Binding ImageUrl}" Width="160" Height="160"/> </DataTemplate> </ListBox.ItemTemplate> </ListBox> </ScrollViewer>\[/code\]My xml file:\[code\] <?xml version="1.0" encoding="utf-8" ?><Image ImageUrl = "C:/Users/USER 1/Documents/Visual Studio 2012/Projects/pinchimage/pinchimage/Butterfly.jpg"/> <Image ImageUrl="C:/Users/USER 1/Documents/Visual Studio 2012/Projects/pinchimage/pinchimage/Desert.jpg"/> <Image ImageUrl="C:/Users/USER 1/Documents/Visual Studio 2012/Projects/pinchimage/pinchimage/Field.jpg"/><images> <Image ImageUrl = "C:/Users/USER 1/Documents/Visual Studio 2012/Projects/pinchimage/pinchimage/Butterfly.jpg"/> <Image ImageUrl="C:/Users/USER 1/Documents/Visual Studio 2012/Projects/pinchimage/pinchimage/Desert.jpg"/></images>\[/code\]Manipage.xaml.cs:\[code\]private void imglist_Loaded(object sender, RoutedEventArgs e) { var element = XElement.Load("Authors.xml"); var authors = from var in element.Descendants("Image") select new images { ImageUrl = GetImage(var.Attribute("ImageUrl").Value) }; imglist.ItemsSource = authors; } private ImageSource GetImage(string p) { return new BitmapImage(new Uri(p, UriKind.Relative)); }\[/code\]class file:\[code\]public class images{ public ImageSource ImageUrl { get; set; }}\[/code\]
 
Back
Top