Exemplo n.º 1
0
        // 增加一个文件夹引用到图片库
        private async void btnAddFolder_Click(object sender, RoutedEventArgs e)
        {
            Windows.Storage.StorageLibrary picturesLibrary = await Windows.Storage.StorageLibrary.GetLibraryAsync(KnownLibraryId.Pictures);

            // 弹出文件夹选择器,以选择需要添加到图片库的文件夹
            StorageFolder addedFolder = await picturesLibrary.RequestAddFolderAsync();

            if (addedFolder != null)
            {
                // 添加成功
                _addedFloders.Add(addedFolder);
            }
            else
            {
            }
        }
Exemplo n.º 2
0
        // 从图片库移除之前添加的全部文件夹引用
        private async void btnRemoveFolder_Click(object sender, RoutedEventArgs e)
        {
            Windows.Storage.StorageLibrary picturesLibrary = await Windows.Storage.StorageLibrary.GetLibraryAsync(KnownLibraryId.Pictures);

            foreach (StorageFolder folder in _addedFloders)
            {
                // 从图片库移除指定的文件夹引用
                if (await picturesLibrary.RequestRemoveFolderAsync(folder))
                {
                    // 移除成功
                }
                else
                {
                }
            }
        }
Exemplo n.º 3
0
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            // 注意:要想访问图片库,别忘了增加 <Capability Name="picturesLibrary" />

            // 获取图片库的 StorageLibrary 对象
            Windows.Storage.StorageLibrary picturesLibrary = await Windows.Storage.StorageLibrary.GetLibraryForUserAsync(null, KnownLibraryId.Pictures);

            // 当前库所包含的文件夹增多或减少时
            picturesLibrary.DefinitionChanged += async(Windows.Storage.StorageLibrary innerSender, object innerEvent) =>
            {
                await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                {
                    lblMsg.Text = "图片库所包含的文件夹如下:";
                    foreach (StorageFolder folder in picturesLibrary.Folders) // 当前库所包含的全部文件夹
                    {
                        lblMsg.Text += Environment.NewLine;
                        lblMsg.Text += folder.Path;
                    }
                });
            };

            base.OnNavigatedTo(e);
        }
    private async void GetPicturesFolderAsync()
    {
        Windows.Storage.StorageLibrary picturesStorage = await Windows.Storage.StorageLibrary.GetLibraryAsync(Windows.Storage.KnownLibraryId.Pictures);

        pictureFolderPath = picturesStorage.SaveFolder.Path;
    }