【WP7】关于磁贴的使用
WP7的磁铁分为两种:程序磁贴 和 次要磁贴
属性: Title 正面标题
BackgroundImage 正面背景图
Count 计数器,从 1 到 99 的整数值。如果未设置值或者设置为 0,则不会在磁贴上显示
BackTitle 背面标题
BackBackgroundImage 背面背景图
BackContent 背面内容
~ 第三方应用程序不能自定义磁贴的属性,不能自定义磁贴的行为
~ 磁贴图片:不能大于 80K, 173*173像素(自动拉伸适应)
~ 当图像因某些原因无法加载时,其他属性也不会更新
磁贴的设置和使用(次要磁贴):
- ShellTitle:
1、创建磁贴
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
ShellTile TileToFind = ShellTile.ActiveTiles.FirstOrDefault(x => x.NavigationUri.ToString().Contains("DefaultTitle=FromTile")); //判断磁贴是否已经存在 if (TileToFind == null) { //设置磁贴数据 StandardTileData NewTileData = new StandardTileData { BackgroundImage = new Uri("background.jpg", UriKind.Relative), Title = "标题", Count = 12, BackTitle = "背面标题", BackContent = "背面内容", BackBackgroundImage = new Uri("backbackground.jpg", UriKind.Relative) }; //创建磁贴 ShellTile.Create(new Uri("/NewPage.xaml?DefaultTitle=FromTile", UriKind.Relative), NewTileData); }
2、更新磁贴
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
ShellTile TileToFind = ShellTile.ActiveTiles.FirstOrDefault(x => x.NavigationUri.ToString().Contains("DefaultTitle=FromTile")); if (TileToFind != null) { StandardTileData NewData = new StandardTileData { Title = "新标题", BackgroundImage = new Uri(uri, UriKind.Relative) }; TileToFind.Update(NewData); }
3、删除磁贴
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
ShellTile TileToFind = ShellTile.ActiveTiles.FirstOrDefault(x => x.NavigationUri.ToString().Contains("DefaultTitle=FromTile")); if (TileToFind != null) { TileToFind.Delete(); }
应用程序磁贴初始属性设置
WMAppManifest.xml 文件中编辑 Tokens 元素来设置这些值
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
WMAppManifest.xml <PrimaryToken TokenID="TilesDemoToken" TaskName="_default"> <TemplateType5> <BackgroundImageURI IsRelative="true" IsResource="false">Background.png</BackgroundImageURI> <Count>0</Count> <Title>TilesDemo</Title> </TemplateType5> </PrimaryToken>
计划更新磁贴(更新磁贴背景)
ShellTileSchedule 允许您设置将更新磁贴的背景图像的一次性计划或定期计划。即使您的应用程序处于非活动状态,该计划仍然可以继续运行。ShellTileSchedule 还可以用于停止为您的应用程序运行的任何计划。每当应用程序由于计划失败而启动时,应用程序都应该存储其 ShellTileSchedule 设置并启动该计划,即使应用程序不再运行,也可以取消计划。
更新应用程序磁贴:
ShellTileSchedule SampleTileSchedule = new ShellTileSchedule();
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
SampleTileSchedule.Recurrence = UpdateRecurrence.Onetime; SampleTileSchedule.StartTime = DateTime.Now; SampleTileSchedule.RemoteImageUri = new Uri(@"http://7.su.bdimg.com/icon/54.png"); SampleTileSchedule.Start(); TileScheduleRunning = true;
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
SampleTileSchedule.Interval = UpdateInterval.EveryHour; SampleTileSchedule.Recurrence = UpdateRecurrence.Interval; SampleTileSchedule.RemoteImageUri = new Uri(@"http://7.su.bdimg.com/icon/54.png"); SampleTileSchedule.Start(); TileScheduleRunning = true;
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
SampleTileSchedule.Interval = UpdateInterval.EveryHour; SampleTileSchedule.MaxUpdateCount = 50; SampleTileSchedule.Recurrence = UpdateRecurrence.Interval; SampleTileSchedule.RemoteImageUri = new Uri(@"http://7.su.bdimg.com/icon/54.png"); SampleTileSchedule.Start(); TileScheduleRunning = true;
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
if (!TileScheduleRunning) { buttonIndefinite_Click(sender, e); } SampleTileSchedule.Stop(); TileScheduleRunning = false;
更新次要磁贴:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
foreach (ShellTile TileToSchedule in ShellTile.ActiveTiles) { ShellTileSchedule mySchedule = new ShellTileSchedule(TileToSchedule); mySchedule.Interval = UpdateInterval.EveryHour; mySchedule.Recurrence = UpdateRecurrence.Interval; mySchedule.RemoteImageUri = imageURI; mySchedule.Start(); }