Exemplo n.º 1
0
        private void AddFile(TreeViewItem item, string filename)
        {
            var fileItem = new TreeViewItem();

            fileItem.Header = new FileInfo(filename).Name;
            fileItem.Tag    = filename;
            TreeViewItemProps.SetIsFile(fileItem, true);
            fileItem.MouseDoubleClick += (s, args) =>
            {
                if (this.FileSelected != null)
                {
                    this.FileSelected(fileItem, new StringEventArgs(filename));
                }
            };
            fileItem.PreviewKeyDown += (s, args) =>
            {
                if (args.Key == System.Windows.Input.Key.Enter)
                {
                    if (this.FileSelected != null)
                    {
                        this.FileSelected(fileItem, new StringEventArgs(filename));
                    }
                    args.Handled = true;
                }
            };
            item.Items.Add(fileItem);
        }
Exemplo n.º 2
0
        void txtRoot_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (Directory.Exists(this.txtRoot.Text))
            {
                foldersTree.Items.Clear();
                TreeViewItem item = new TreeViewItem();
                item.Header = new DirectoryInfo(this.txtRoot.Text).Name;
                item.Tag    = Path.GetFullPath(this.txtRoot.Text);
                item.Items.Add(_dummyNode);
                item.Expanded += folder_Expanded;

                // Apply the attached property so that
                // the triggers know that this is root item.
                TreeViewItemProps.SetIsRootLevel(item, true);
                foldersTree.Items.Add(item);
            }
        }