这是我的代码,我将1个图像从本地文件夹复制到我的应用程序存储文件夹,然后显示磁贴通知。请帮我复制所有图像,然后复制图块通知中显示的这些图像。
namespace Tiles
{
public sealed partial class BlankPage : Page
{
string imageRelativePath = String.Empty;
public BlankPage()
{
this.InitializeComponent();
CopyImages();
}
public async void CopyImages()
{
FileOpenPicker picker = new Windows.Storage.Pickers.FileOpenPicker();
picker.ViewMode = PickerViewMode.Thumbnail;
picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
picker.FileTypeFilter.Add(".jpg");
picker.FileTypeFilter.Add(".jpeg");
picker.FileTypeFilter.Add(".png");
picker.CommitButtonText = "Copy";
StorageFile file = await picker.PickSingleFileAsync();
StorageFile newFile = await Windows.Storage.ApplicationData.Current.LocalFolder.CreateFileAsync(file.Name);
await file.CopyAndReplaceAsync(newFile);
this.imageRelativePath = newFile.Path.Substring(newFile.Path.LastIndexOf("\\") + 1);
IWideTileNotificationContent tileContent = null;
ITileWideImage wideContent = TileContentFactory.CreateTileWideImage();
wideContent.RequireSquareContent = false;
wideContent.Image.Src = "ms-appdata:///local/" + this.imageRelativePath;
wideContent.Image.Alt = "App data";
tileContent = wideContent;
tileContent.RequireSquareContent = false;
TileUpdateManager.CreateTileUpdaterForApplication().Update(tileContent.CreateNotification());
}
}
}
答案 0 :(得分:0)
您应该致电.PickSingleFileAsync()
,而不是致电.PickMultipleFileAsync()
。有关如何获取所有文件名的示例,请参阅PickMultipleFileAsync Docs。
您现在拥有的代码可以复制一个文件并创建一个磁贴,应该通过一个遍历.PickMultipleFileAsync()
我没有对此进行测试,但它应该看起来像这样:
FilePickerSelectedFilesArray files = await picker.PickMultipleFileAsync();
for (var i = 0; i < files.size; i++)
{
StorageFile newFile = await
Windows.Storage.ApplicationData.Current.LocalFolder
.CreateFileAsync(files[1].Name);
await file.CopyAndReplaceAsync(newFile);
this.imageRelativePath = newFile.Path.Substring(
newFile.Path.LastIndexOf("\\") + 1);
IWideTileNotificationContent tileContent = null;
ITileWideImage wideContent = TileContentFactory.CreateTileWideImage();
wideContent.RequireSquareContent = false;
wideContent.Image.Src = "ms-appdata:///local/" + this.imageRelativePath;
wideContent.Image.Alt = "App data";
tileContent = wideContent;
tileContent.RequireSquareContent = false;
TileUpdateManager.CreateTileUpdaterForApplication().Update(
tileContent.CreateNotification());
}