最近刚开始做windows phone日历应用的开发,程序要实现磁贴的更新,我的做法是这样的:
1、启动程序后后台任务就启动,定时调用函数就行判断更新
在ScheduledAgent.cs 中创建一个函数
if (task.Name == GlobalAttributes.REFRESH_AGENT_NAME)
{
RefreshTile();
NotifyComplete();
}
2、由于我需要本地产生背景图片,所以我考虑的本地绘图,不懂的可以参看这里http://www.cnblogs.com/alexis/archive/2011/07/22/2113253
于是我创建了一个工程,里面仅包含一个 windows phone user control页面,前台布局如下:
<Grid x:Name="LayoutRoot">
<Grid x:Name="xamlGrid" Width="173" Height="173" >
<Image Source="/365Plus;component/Images/Default.jpg" HorizontalAlignment="Left"
Name="image1" Stretch="Fill"
VerticalAlignment="Top" />
<TextBlock HorizontalAlignment="Left" Margin="5,5,0,0" Name="YearAndMonthTextBlock" Text="2012年12月" VerticalAlignment="Top" FontFamily="Portable User Interface" FontSize="20" />
<TextBlock HorizontalAlignment="Left" FontFamily="Portable User Interface" Margin="5,35,0,0" Name="DayTextBlock" Text="20日" VerticalAlignment="Top" FontSize="35" />
<TextBlock HorizontalAlignment="Left" FontFamily="Portable User Interface" Margin="85,55,0,0" Name="WeekTextBlock" Text="周四" VerticalAlignment="Top" FontSize="20" />
<TextBlock HorizontalAlignment="Left" FontFamily="Portable User Interface" Margin="5,129,0,0" Name="LunarTextBlock" Text="初八" VerticalAlignment="Top" FontSize="26" />
</Grid>
</Grid>
在后台代码中这样写
public Tile()
{
InitializeComponent();
//判断是否是当前日期,如果不是就刷新页面
if (_365Settings.GetDateForTile().Date != DateTime.Today)
{
CreateAndModify();
}
}
public void CreateAndModify()