我已经看到一些示例显示CycleTile正在运行,但这些都使用了本地图像.一旦应用程序首次运行,是否可以设置这些图像并将CycleTile指向远程图像?或者如果我确实需要先将这些保存到手机中,我怎样才能让CycleTile引用它们?
Jus*_*gel 21
CycleTileTemplate和CycleTileData仅支持本地URI,不支持远程Web URI.这意味着您只能从通过XAP安装的文件或从IsoStore中的文件设置循环映像的源.
为了支持CycleTileData中的远程图像,您需要在定期后台代理中下载图像,将它们保存到IsoStore,然后使用这些图像更新CycleTileData.推送通知在这里不起作用,因为图像需要是本地的,ShellTileSchedule也不是.
确保将图像保存到"/ Shared/ShellContent"下的IsoStore,并将其URI设置为"isostore:/Shared/Shellcontent/myImage.png",否则开始屏幕图块将无法访问它们.
让我们看一个例子.首先,我们首先编写一个并行线程算法,启动9个下载线程,等待结果,然后更新磁贴:
private IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication();
private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
var threadFinishEvents = new List<WaitHandle>();
DownloadImages(threadFinishEvents);
new Thread(()=>
{
Mutex.WaitAll(threadFinishEvents.ToArray());
UpdateTiles();
isoStore.Dispose();
}).Start();
}
Run Code Online (Sandbox Code Playgroud)
接下来,我们将9个图像下载到IsoStore"/ Shared/ShellContent".我们将特别注意为每个Web下载添加新的线程标记,并在文件位于IsoStore后将标志设置为已完成.
private void DownloadImages(List<WaitHandle> threadFinishEvents)
{
for (int i = 0; i < 9; i++)
{
var localI = i;
var threadFinish = new EventWaitHandle(false, EventResetMode.ManualReset);
threadFinishEvents.Add(threadFinish);
var request = WebRequest.CreateHttp("http://www.justinangel.net/storage/691x336.png");
request.BeginGetResponse(ir =>
{
var result = request.EndGetResponse(ir);
using (var isoStoreFile = isoStore.OpenFile("shared/shellcontent/myImage" + localI + ".png",
FileMode.Create,
FileAccess.ReadWrite))
using (var response = result.GetResponseStream())
{
var dataBuffer = new byte[1024];
while (response.Read(dataBuffer, 0, dataBuffer.Length) > 0)
{
isoStoreFile.Write(dataBuffer, 0, dataBuffer.Length);
}
}
threadFinish.Set();
}, null);
}
}
Run Code Online (Sandbox Code Playgroud)
最后,我们将更新实时磁贴以使用IsoStore中的新映像.
private void UpdateTiles()
{
ShellTile.ActiveTiles
.First()
.Update(new CycleTileData()
{
Title = "Cyclical",
CycleImages = new Uri[]
{
new Uri("isostore:/Shared/ShellContent/myImage0.png", UriKind.Absolute),
new Uri("isostore:/Shared/ShellContent/myImage1.png", UriKind.Absolute),
new Uri("isostore:/Shared/ShellContent/myImage2.png", UriKind.Absolute),
new Uri("isostore:/Shared/ShellContent/myImage3.png", UriKind.Absolute),
new Uri("isostore:/Shared/ShellContent/myImage4.png", UriKind.Absolute),
new Uri("isostore:/Shared/ShellContent/myImage5.png", UriKind.Absolute),
new Uri("isostore:/Shared/ShellContent/myImage6.png", UriKind.Absolute),
new Uri("isostore:/Shared/ShellContent/myImage7.png", UriKind.Absolute),
new Uri("isostore:/Shared/ShellContent/myImage8.png", UriKind.Absolute),
}
});
}
Run Code Online (Sandbox Code Playgroud)
有几个有趣的事情需要考虑:
| 归档时间: |
|
| 查看次数: |
3141 次 |
| 最近记录: |