コード例 #1
0
ファイル: MainWindow.xaml.cs プロジェクト: rcdavis/Archiver
        private void AddFolder_Click(object sender, RoutedEventArgs e)
        {
            AddTreeFolderDialog dialog = new AddTreeFolderDialog();

            if (dialog.ShowDialog().GetValueOrDefault(false))
            {
                TreeViewItem selectedItem = root;
                if (treeView.SelectedItem != null)
                {
                    selectedItem = (TreeViewItem)treeView.SelectedItem;
                }

                ArchiveProjectEntry entry = new ArchiveProjectEntry
                {
                    Name = dialog.FolderName
                };
                ((ArchiveProjectEntry)selectedItem.Header).AddChild(entry);

                TreeViewItem item = new TreeViewItem()
                {
                    Header = entry
                };
                selectedItem.Items.Add(item);
                selectedItem.IsExpanded = true;
            }
        }
コード例 #2
0
ファイル: MainWindow.xaml.cs プロジェクト: rcdavis/Archiver
        private void TreeViewItem_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            if (treeView.SelectedItem != null && treeView.SelectedItem != root)
            {
                TreeViewItem        item   = treeView.SelectedItem as TreeViewItem;
                AddTreeFolderDialog dialog = new AddTreeFolderDialog
                {
                    FolderName = item.Header.ToString()
                };

                if (dialog.ShowDialog().GetValueOrDefault(false))
                {
                    ArchiveProjectEntry entry = item.Header as ArchiveProjectEntry;
                    entry.Name = dialog.FolderName;
                    // HACK: Must force the Header to change in order for the text to
                    // display correctly in the TreeView.
                    item.Header = null;
                    item.Header = entry;
                }
            }
        }