示例#1
0
        public async static Task LoadDemoData()
        {
            StorageFolder appInstalledFolder = Package.Current.InstalledLocation;
            StorageFolder albumsFolder       = await appInstalledFolder.GetFolderAsync(@"Assets\Albums");

            var fileTypesFilter = new List <string>
            {
                ".png", ".jpg", ".jpeg", ".bmp", ".gif", ".tiff", ".jxr", ".ico" //, ".svg"
                // *.svg files are supported in Windows 10, starting from version 1703
            };

            QueryOptions queryOptions = new QueryOptions(CommonFileQuery.OrderByName, fileTypesFilter);

            foreach (var folder in await albumsFolder.GetFoldersAsync())
            {
                var album = new AlbumViewModel {
                    Title = folder.Name
                };

                if (folder.Name == DEMO_MAIN_ALBUM && MainAlbum == null)
                {
                    album.IsMain = true;
                }

                AddAlbum(album);

                var files = await folder.CreateFileQueryWithOptions(queryOptions).GetFilesAsync();

                foreach (var file in files)
                {
                    try
                    {
                        var photo = await album.AddPhoto(file);

                        photo.PopulateWithRandomData(file.DisplayName.SplitCamelCase());
                    }
                    catch (Exception ex)
                    {
                        await Utils.ShowContentDialog("Add Photo", ex.Message);
                    }
                }
            }
        }