void win_WpfDemo_Loaded(object sender, RoutedEventArgs e) { foreach (string s in Directory.GetLogicalDrives()) { DirectoryEntry d = new DirectoryEntry(s, s, "<Driver>", "<DIR>", Directory.GetLastWriteTime(s), "Images/dir.gif", EntryType.Dir); entries.Add(d); } this.list_FolderBrowser.DataContext = entries; text_GridDescr.Text = "The most familiar container control is the Grid control. By default, each new Window opened in the Windows Presentation Foundation (WPF) Designer for Visual Studio includes a Grid control. The Grid allows you to position controls within user-definable cells. Controls placed in cells maintain a fixed margin between two or more control edges and cell edges when the Window is resized. For more information about how to set the margins, see How to: Set Margins for a Control in the WPF Designer.\n\n" + "When added to a Window, a Grid control consists of a single cell. Additional vertical and horizontal rows can be added in code or in the WPF Designer. For more information, see How to: Add Rows and Columns to a Grid."; oListBoxItem_01.Content = "hoom\tplup"; oListBoxItem_02.Content = "antidisestablishmentarianism\tplup"; textbox_Scrolling.Text = "The Goops they lick their fingers,\n" + " And the Goops they lick their knives;\n" + "They spill their broth on the tablecloth --\n" + " Oh, they lead disgusting lives!\n" + "The Goops they talk while eating,\n" + " And loud and fast they chew;\n" + "And that is why I’m glad that I\n" + " Am not a Goop -- are you?\n"; }
private void list_FolderBrowser_SelectionChanged(object sender, SelectionChangedEventArgs e) { DirectoryEntry entry = (DirectoryEntry)list_FolderBrowser.Items[list_FolderBrowser.SelectedIndex]; text_CurrentPath.Text = entry.Fullpath; if (entry.Type == EntryType.Dir) { subEntries.Clear(); try { foreach (string s in Directory.GetDirectories(entry.Fullpath)) { DirectoryInfo dir = new DirectoryInfo(s); DirectoryEntry d = new DirectoryEntry( dir.Name, dir.FullName, "<Folder>", "<DIR>", Directory.GetLastWriteTime(s), "i/icon16-folder.ico", EntryType.Dir); subEntries.Add(d); } foreach (string f in Directory.GetFiles(entry.Fullpath)) { FileInfo file = new FileInfo(f); DirectoryEntry d = new DirectoryEntry( file.Name, file.FullName, file.Extension, file.Length.ToString(), file.LastWriteTime, "i/icon16-file.ico", EntryType.File); subEntries.Add(d); } } catch (Exception ex) { Prompt = ex.Message; MessageBox.Show(Prompt, "Problem", MessageBoxButton.OK, MessageBoxImage.Error); } finally { list_Files.DataContext = subEntries; } } }
private void text_CurrentPath_TextChanged(object sender, TextChangedEventArgs e) { if (list_Files != null) { subEntries.Clear(); try { if (Directory.Exists(text_CurrentPath.Text)) { foreach (string s in Directory.GetDirectories(text_CurrentPath.Text)) { DirectoryInfo dir = new DirectoryInfo(s); DirectoryEntry d = new DirectoryEntry( dir.Name, dir.FullName, "<Folder>", "<DIR>", Directory.GetLastWriteTime(s), "Images/folder.gif", EntryType.Dir); subEntries.Add(d); } foreach (string f in Directory.GetFiles(text_CurrentPath.Text)) { FileInfo file = new FileInfo(f); DirectoryEntry d = new DirectoryEntry( file.Name, file.FullName, file.Extension, file.Length.ToString(), file.LastWriteTime, "Images/file.gif", EntryType.File); subEntries.Add(d); } list_Files.DataContext = subEntries; } } catch (Exception ex) { Prompt = ex.Message; MessageBox.Show(Prompt, "Problem", MessageBoxButton.OK, MessageBoxImage.Error); } } }
private void list_Files_MouseDoubleClick(object sender, MouseButtonEventArgs e) { // ↑↑ Exit if we don't have a valid selection. if (list_Files.SelectedIndex < 0) return; DirectoryEntry entry = (DirectoryEntry)list_Files.Items[list_Files.SelectedIndex]; text_CurrentPath.Text = entry.Fullpath; if (entry.Type == EntryType.Dir) { subEntries.Clear(); try { foreach (string s in Directory.GetDirectories(entry.Fullpath)) { DirectoryInfo dir = new DirectoryInfo(s); DirectoryEntry d = new DirectoryEntry( dir.Name, dir.FullName, "<Folder>", "<DIR>", Directory.GetLastWriteTime(s), "Images/folder.gif", EntryType.Dir); subEntries.Add(d); } foreach (string f in Directory.GetFiles(entry.Fullpath)) { FileInfo file = new FileInfo(f); DirectoryEntry d = new DirectoryEntry( file.Name, file.FullName, file.Extension, file.Length.ToString(), file.LastWriteTime, "Images/file.gif", EntryType.File); subEntries.Add(d); } } catch (Exception ex) { Prompt = ex.Message; MessageBox.Show(Prompt, "Problem", MessageBoxButton.OK, MessageBoxImage.Error); } finally { list_Files.DataContext = subEntries; } } }