I want to display the data extracted before in a customized list, but the method i found to extract that data doesn’t make things easy for me , so i would find a way to display my data without changing the xml reading method.
This is how i want my list to be(xml):
<ListBox Height="516" HorizontalAlignment="Left" Margin="16,74,0,0" Name="listBox1" VerticalAlignment="Top" Width="430" >
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Height="132">
<Image Source="{Binding wkpinImage}" Height="73" Width="73" VerticalAlignment="Top" Margin="0,10,8,0"/>
<StackPanel Width="370">
<TextBlock Text="{Binding Day}" Foreground="#FFC8AB14" FontSize="28" />
<TextBlock Text="{Binding Low}" TextWrapping="Wrap" FontSize="24" />
<TextBlock Text="{Binding High}" TextWrapping="Wrap" FontSize="24" />
<TextBlock Text="{Binding Condition}" TextWrapping="Wrap" FontSize="26" />
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
And this is the xml reading method(c#):
while (reader.Read())
{
switch (reader.Name)
{
case ("day_of_week"):
{
listBox1.Items.Add(new ListBoxItem()
{
Content = reader.GetAttribute("data")
});
Day = Content.ToString();
} break;
…
I would recommend using MVVM approach to bind items to your listbox.
Here is a very good tutorial of how to MVVM to bind items to a listbox:
http://www.labo-dotnet.com/post/Creating-your-first-MVVM-silverlight-application-on-windows-phone-7.aspx
There are lot’s of good points about MVVM: