private void SelectEntry(string remainingSelectPath, BackgroundStorageDirectory currentNode, TreeViewItem currentContainer) { var i = remainingSelectPath.IndexOf('\\'); if (i >= 0) { string next = remainingSelectPath.Substring(0, i); remainingSelectPath = remainingSelectPath.Substring(i + 1); currentNode = currentNode.Directories.First((dir) => dir.Name == next); currentContainer = currentContainer.ItemContainerGenerator.ContainerFromItem(currentNode) as TreeViewItem; currentContainer.IsExpanded = true; currentContainer.ItemContainerGenerator.StatusChanged += (sender, args) => { if (currentContainer.ItemContainerGenerator.Status == System.Windows.Controls.Primitives.GeneratorStatus.ContainersGenerated) { SelectEntry(remainingSelectPath, currentNode, currentContainer); } }; } else { imageListView.SelectedItem = currentNode.Files.Where(file => file.Name == remainingSelectPath).SingleOrDefault(); currentContainer.IsSelected = true; currentContainer.BringIntoView(); imageListView.Focus(); } }
private void ListBackgroundEntries(BackgroundStorageDirectory parent, StringBuilder sb, bool recursive = false) { foreach (var subdir in parent.Directories) { sb.Append(subdir.Path); sb.Append('\n'); if (recursive) { ListBackgroundEntries(subdir, sb, true); } } foreach (var file in parent.Files) { sb.Append(file.Path); sb.Append('\n'); } }