1

这是我的代码,其中我将 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());
                }
            }
        }
4

1 回答 1

0

Instead of calling .PickSingleFileAsync() you should call .PickMultipleFileAsync(). See PickMultipleFileAsync Docs for an example of how to get all the file names returned.

You code that you have now that copies one file and create a tile, should be surround by a loop that goes through all the files returned by .PickMultipleFileAsync()

I didn't test this, but it should look a little like this:

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()); 
} 
于 2012-04-19T15:18:15.353 回答