im having problems showing data from my xml to my listbox with 2 textblocks.
my xml looks like this:
then my code...Code:<?xml version="1.0" ?> <book> <article id="1" articleno="i" title="Introduction" section="" content="Content here..." /> <article id="2" articleno="p" title="Preamble" section="" content="Content here..." /> <article id="3" articleno="1" title="Scope and Limitations" section="Section 1" content="Section 1. Content here..." /> <article id="4" articleno="1" title="Scope and Limitations" section="Section 2" content="Section 2. Content here..." /> </book>
and my xaml..Code:XDocument data = XDocument.Load("book.xml"); var filteredData = from c in data.Descendants("article") where c.Attribute("articleno").Value == "1" select new Book() { ArticleNo = c.Attribute("articleno").Value, Title = c.Attribute("title").Value, Section = c.Attribute("section").Value, Content = c.Attribute("content").Value }; listContents1.ItemsSource = filteredData;
on this one.. its supposed to show the last 2 data in my xml.. but instead its showing the last data in my xml 2 times.Code:<ListBox x:Name="listContents1" Grid.Row="1" Height="600"> <ListBox.ItemTemplate> <DataTemplate> <StackPanel Height="auto" HorizontalAlignment="Left" Margin="12,0,0,12" Name="stackPanel2" VerticalAlignment="Top" Width="444" Grid.Row="1"> <TextBlock Height="auto" Name="txSection" Text="{Binding Section}" FontSize="36" Margin="0,0,0,0" Foreground="White" /> <TextBlock Height="auto" Name="txContent" Text="{Binding Content}" Style="{StaticResource PhoneTextSubtleStyle}" Margin="0,0,0,0" TextTrimming="WordEllipsis" /> </StackPanel> </DataTemplate> </ListBox.ItemTemplate> </ListBox>
kinda like:
section 1.
section 2.
but instead im getting:
section 2.
section 2.
i really dont see the problem.. could it bee in my xaml? my query in my linq is correct (i think)
please help. thanks.

Reply With Quote



