C# 是否随时间推移刷新页面上的信息?
我有一个主页,它根据currentTime从本地xml文件获取信息 当应用程序启动时,它会检查当前时间,并根据该时间获取正确的xml值,并在textblock中显示。但它没有更新。我正考虑在页面上添加一个刷新按钮,但更聪明的人建议使用DispatchTimer或Timer。我应该使用什么,我应该把代码放在哪里?我是一个非常基础的用户,所以如果你能具体一点并给出代码示例,我将不胜感激 谢谢大家:)我的一小部分代码C# 是否随时间推移刷新页面上的信息?,c#,windows-phone-7,C#,Windows Phone 7,我有一个主页,它根据currentTime从本地xml文件获取信息 当应用程序启动时,它会检查当前时间,并根据该时间获取正确的xml值,并在textblock中显示。但它没有更新。我正考虑在页面上添加一个刷新按钮,但更聪明的人建议使用DispatchTimer或Timer。我应该使用什么,我应该把代码放在哪里?我是一个非常基础的用户,所以如果你能具体一点并给出代码示例,我将不胜感激 谢谢大家:)我的一小部分代码 var obj = filteredData.First(); T
var obj = filteredData.First();
TimeSpan currentTime = myDay.TimeOfDay;
string result = String.Empty;
string Prayer = String.Empty;
if (currentTime >= obj.Fajr && currentTime < obj.Sunrise)
{
result = "Fajr";
Prayer = obj.Fajr.ToString(@"hh\:mm");
}
else if (currentTime >= obj.Sunrise && currentTime < obj.Zohr)
{
result = "Sunrise";
Prayer = obj.Sunrise.ToString(@"hh\:mm");
}
textBlock3.Text = result;
textBlock4.Text = Prayer;
var obj=filteredData.First();
TimeSpan currentTime=myDay.TimeOfDay;
字符串结果=string.Empty;
string Prayer=string.Empty;
如果(当前时间>=obj.Fajr&¤tTime=obj.Sunrise&¤tTime
使用视图模型和背景线程可能会更好地实现这一点,例如:
公共类prairviewmodel:DependencyObject
公共祈祷者模型()
{
//TODO:启动一个新线程,在正确的时间为每个属性引发PropertyChanged()事件
}
公共字符串结果
{
得到
{
TimeSpan currentTime=myDay.TimeOfDay;
如果(当前时间>=obj.Fajr&¤tTime=obj.Sunrise&¤tTime=obj.Fajr&¤tTime=obj.Sunrise&¤tTime
public class PrayerViewModel : DependencyObject
public PrayerViewModel ()
{
// TODO: Start off a new thread that Raises the PropertyChanged() Event for each property at the right time
}
public string Result
{
get
{
TimeSpan currentTime = myDay.TimeOfDay;
if (currentTime >= obj.Fajr && currentTime < obj.Sunrise)
{
return "Fajr";
}
else if (currentTime >= obj.Sunrise && currentTime < obj.Zohr)
{
return "Sunrise";
}
}
}
public string Prayer
{
get
{
TimeSpan currentTime = myDay.TimeOfDay;
if (currentTime >= obj.Fajr && currentTime < obj.Sunrise)
{
Prayer = obj.Fajr.ToString(@"hh\:mm");
}
else if (currentTime >= obj.Sunrise && currentTime < obj.Zohr)
{
Prayer = obj.Sunrise.ToString(@"hh\:mm");
}
}
}
}