Need to Update contents in windows phone page automatically after fixed intervals the data is fetched from as json from web
the data is Live Scores of a Football Match in json format
The LiveScoresJson.cs file is
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Surfer
{
class LiveSocresJson
{
public class Customer
{
public string name { get; set; }
}
public class Match
{
public int id { get; set; }
public string status { get; set; }
public string home { get; set; }
public string homepath { get; set; }
public string away { get; set; }
public string awaypath { get; set; }
public string competition { get; set; }
public string competitionkey { get; set; }
public List<int> score { get; set; }
public List<object> events { get; set; }
public string scores { get; set; }
}
public class RootObject
{
public Customer customer { get; set; }
public List<Match> matches { get; set; }
}
}
}
i used the following code to get json data
public async void JSON()
{
String Url = "url of the source";
WebClient Client = new WebClient();
Client.Headers["Accept"] = "application/json";
Client.DownloadStringAsync(new Uri(Url));
Client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(JsonFuction);
}
private void JsonFuction(object sender, DownloadStringCompletedEventArgs e)
{
try
{
var Data = JsonConvert.DeserializeObject<LiveSocresJson.RootObject>(e.Result);
foreach (var d in Data.matches)
{
string img = d.homepath;
string url = "Assets/Images/" + img + ".png";
`enter code here` d.homepath = url;
string img2 = d.awaypath;
string url2 = "Assets/Images/" + img2 + ".png";
d.awaypath = url2;
var f = d.score;
string scoresg = d.score[0] +"-" +d.score[1];
d.scores = scoresg;
}
TableContent.ItemsSource = Data.matches;
}
catch (Exception ex)
{ }
}
with this code the contents are loaded each time when the page is loaded but, what i need is to update the page after fixed intervals so that i can keep the Live Scores updated in my page what should i do?
The xaml code i used is
<StackPanel >
<StackPanel Height="60" Background="Black" VerticalAlignment="Top" >
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" Height="60">
<TextBlock Text="Live Matches" Width="Auto" Foreground="White" FontSize="25" Margin="10,0,0,0" Height="40" HorizontalAlignment="Center" VerticalAlignment="Center" />
</StackPanel>
</StackPanel>
<Grid x:Name="La">
<ScrollViewer Name="ScrollViewer" Margin="0,0,0,12" VerticalAlignment="Top" VerticalScrollBarVisibility="Visible" ManipulationMode="Control">
<ListBox x:Name="TableContent" VerticalAlignment="Bottom" Height="505" Width="Auto">
<ListBox.ItemTemplate >
<DataTemplate>
<Grid x:Name="gh">
<StackPanel Height="100" Background="Transparent" Margin="0,0,0,0" Width="663" Orientation="Vertical" VerticalAlignment="Bottom">
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" Height="100" Width="Auto">
<TextBlock Text="{Binding status}" Width="Auto" Foreground="Black" FontSize="22" Margin="7,0,0,0" Height="40" VerticalAlignment="Center" />
<Image Source="{Binding homepath}" Height="40" Width="40" VerticalAlignment="Center" Margin="10,0,0,0"/>
<TextBlock Text="{Binding home}" Width="100" Foreground="Black" FontSize="22" Margin="10,0,0,0" Height="40" VerticalAlignment="Center" />
<TextBlock Text="{Binding scores}" Width="50" Foreground="Black" FontSize="25" Margin="10,0,0,0" Height="40" VerticalAlignment="Center" HorizontalAlignment="Center"/>
<Image Source="{Binding awaypath}" Height="40" Width="40" VerticalAlignment="Center" Margin="15,0,0,0"/>
<TextBlock Text="{Binding away}" Width="Auto" Foreground="Black" FontSize="22" Margin="10,0,0,0" Height="40" VerticalAlignment="Center" />
</StackPanel>
</StackPanel>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</ScrollViewer>
</Grid>
</StackPanel>
How can i use the ObservableCollections here and change the contents by binding the list to ObservableCollections instead of Data.matches?