屬性餘米結合網絡的XML,但它的讀數只有第一個記錄綁定網頁XML在列表框中
XML
<?xml version="1.0"?>
<content>
<content_row id="1" day="1" title="test" from="01:10" first_name="jitendra" last_name="shakyawar" about_keynote="test" image="1326091608.jpg" innhold="1" about_speaker="test" desc="" flattr_url=""/>
<content_row id="4" day="1" title="test 4" from="04:20" first_name="" last_name="" about_keynote="" image="" innhold="2" about_speaker="" desc="Test 4" flattr_url=""/>
</content>
XAML:
<cc:TabControl HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,80,0,0">
<cc:TabItem Name="tabDag1" Height="50" Width="80" Header="Dag 1" Style="{StaticResource TabItemStyle1}" Foreground="Black" >
<Grid x:Name="ContentGrid" Grid.Row="1" HorizontalAlignment="Center" Margin="5,0,0,0">
<ListBox Name="listDag1" Width="440" Background="Black">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Height="auto" HorizontalAlignment="Left" Margin="0,20,20,0">
<TextBlock TextWrapping="Wrap" Style="{StaticResource PhoneTextNormalStyle}" Text="{Binding From}" FontWeight="Bold" FontSize="28"/>
<TextBlock TextWrapping="Wrap" Style="{StaticResource PhoneTextNormalStyle}" Text="{Binding FirstName}"/>
<TextBlock TextWrapping="Wrap" Style="{StaticResource PhoneTextNormalStyle}" Text="{Binding LastName}"/>
<TextBlock TextWrapping="Wrap" Style="{StaticResource PhoneTextNormalStyle}" Text="{Binding AboutSpeaker}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</cc:TabItem>
</cc:TabControl>
C#
XDocument xdoc = XDocument.Parse(e.Result);
var data = from query in xdoc.Descendants("content")
select new ContentItems
{
FirstName = (query.Element("content_row") == null) ? "" : (string)query.Element("content_row").Attribute("first_name").Value,
LastName = (query.Element("content_row") == null) ? "" : (string)query.Element("content_row").Attribute("last_name").Value,
From = (query.Element("content_row") == null) ? "" : (string)query.Element("content_row").Attribute("from").Value,
AboutSpeaker = (query.Element("content_row") == null) ? "" : (string)query.Element("content_row").Attribute("about_speaker").Value
};
listDag1.ItemsSource = data;
xdoc.Descendants(「content_row」)爲什麼你不使用這 – 2012-01-11 05:59:09
如果我使用這個,然後顯示空異常錯誤。 – Shri 2012-01-11 07:49:06