private async void UIElement_OnTapped(object sender, TappedRoutedEventArgs e) { var item = ((FrameworkElement)sender).Tag as FileExplorerItem; if (item == null) { return; } if (item.IsFolder) { var folder = FolderTree.First(); if (folder.Path == item.Path) { return; } GetTreeForFolder(await FolderTree.First() .GetFolderAsync(item.Name)); } else { if (SelectionMode == SelectionMode.FileWithOpen) { SelectedSingleItem(item); } } }
private async Task SelectedSingleItem(FileExplorerItem selectedItem) { foreach (FileExplorerItem item in CurrentItems) { if (item != selectedItem) { item.Selected = false; } else { item.Selected = true; if (SelectionMode == SelectionMode.FileWithOpen) { try { IStorageFolderEx folder = FolderTree.First(); IStorageFileEx file = await folder.GetFileAsync(item.Name); if (_player != null) { _player.Dispose(); } if (file != null) { _player = new SamplePlayer(); _player.WithVoicePool(AudioDefines.VoicePool) .WithXAudio(AudioDefines.XAudio) .WithWaveFormat(AudioDefines.WaveFormat) .WithChannelVolume(0.8) .WithInput(file) .BuildAsync().ContinueWith(task => task.Result.Play(), TaskScheduler.Default); } } catch (Exception ex) { Debug.WriteLine(ex.Message); } } } FileExplorerItem targetItem = GetItemFromPath(item.Path); if (item.Selected && targetItem == null) { SelectedItems.Add(item); } else if (!item.Selected && targetItem != null) { SelectedItems.Remove(GetItemFromPath(item.Path)); } } }
private void btnBack_Click(object sender, RoutedEventArgs e) { var check = sender as CheckBox; if (check != null) { check.IsChecked = false; } SelectedSingleItem(null); if (FolderTree.Count > 1) { FolderTree.Pop(); GetTreeForFolder(FolderTree.First()); } else { Dismiss(null); } }
/// <summary> /// Will retrieve the full folder and file tree for a folder from the internal storage. /// </summary> /// <param name="folder">The instance of the folder for which the tree will be retrieved.</param> private async void GetTreeForFolder(IStorageFolderEx folder) { if (!FolderTree.Contains(folder)) { FolderTree.Push(folder); } ProcessSelectedItems(); CurrentItems.Clear(); IEnumerable <IStorageFolderEx> folderList = await folder.GetFoldersAsync(); foreach (IStorageFolderEx _folder in folderList) { FileExplorerItem item = (from c in SelectedItems where c.Path == _folder.Path select c).FirstOrDefault(); var _addItem = new FileExplorerItem { IsFolder = true, Name = _folder.Name, DisplayName = _folder.DisplayName, Path = _folder.Path, Selected = false }; CurrentItems.Add(_addItem); } IEnumerable <IStorageFileEx> fileList = await folder.GetFilesAsync(); if (fileList != null) { foreach (IStorageFileEx _file in fileList) { //FileExplorerItem item = GetItemFromPath(_file.Path); if (((ExtensionRestrictions & (ExtensionRestrictions.Custom | ExtensionRestrictions.InheritManifest)) != 0) && (Extensions.Count != 0)) { string extension = Path.GetExtension(_file.Name); if (Extensions.FindIndex(x => x.Equals(extension, StringComparison.OrdinalIgnoreCase)) != -1) { CurrentItems.Add(new FileExplorerItem { IsFolder = false, Name = _file.Name, DisplayName = _file.Name, Path = _file.Path, Selected = false }); } } else { CurrentItems.Add(new FileExplorerItem { IsFolder = false, Name = _file.Name, Path = _file.Path, DisplayName = _file.Name, Selected = false }); } } } CurrentPath = FolderTree.First() .Path; }