3

これは、Windows 8 メトロ アプリのコードです。ローカル フォルダーからアプリ ストレージ フォルダーに 1 つの画像をコピーすると、タイル通知が表示されます。画像ライブラリからすべての画像を自動コピーし、タイル通知に表示されるこれらの画像を自動コピーするのを手伝ってください。画像ライブラリからすべての画像にアクセスしたりコピーしたりする方法がわかりません... 画像をコピーするためのユーザー インターフェイスがありません。

public seal 部分クラス 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

2 に答える 2

2

最初に画像フォルダーのパスを指定し、IReadOnlyList を介してこれらの画像のリストを作成し、コピー画像のループを終了するように設定します。その後、TileUpdateManager にタイマーを設定します。そしてそれはうまくいくでしょう。

于 2012-05-23T06:03:49.817 に答える
0

PicturesLibrary 内のファイルを列挙するには:

// from my sample app "MetroContractSample" http://metrocontractsample.codeplex.com/documentation
var queryOptions = new QueryOptions(CommonFileQuery.DefaultQuery, new[] { ".jpg", ".png", ".bmp", ".gif", }) { FolderDepth = FolderDepth.Deep, };
StorageFileQueryResult query = KnownFolders.PicturesLibrary.CreateFileQueryWithOptions(queryOptions);
var fileInfoFactory = new FileInformationFactory(query, ThumbnailMode.SingleItem);
IReadOnlyList<FileInformation> fileInfoList = await fileInfoFactory.GetFilesAsync();

注: Package.appxmanifest で PicturesLibrary の機能を宣言する必要があります。

于 2012-05-22T13:27:04.070 に答える