private void MenuRenameFile_Click(object sender, RoutedEventArgs e)
        {
            var selected = TreeFolderBrowser.SelectedItem as PathItem;

            if (selected == null)
            {
                return;
            }

            // Start Editing the file name
            selected.EditName  = selected.DisplayName;
            selected.IsEditing = true;


            var tvItem = GetTreeviewItem(selected);

            if (tvItem != null)
            {
                var tb = WindowUtilities.FindVisualChild <TextBox>(tvItem);
                tb?.Focus();
            }
        }
Ejemplo n.º 2
0
        public void SetTreeViewSelectionByItem(PathItem item, TreeViewItem parentTreeViewItem = null)
        {
            TreeViewItem treeitem = GetNestedTreeviewItem(item);

            if (treeitem != null)
            {
                treeitem.BringIntoView();

                if (treeitem.Parent != null && treeitem.Parent is TreeViewItem)
                {
                    ((TreeViewItem)treeitem.Parent).IsExpanded = true;
                }

                treeitem.IsSelected = true;

                // show edited filename with file stem selected
                if (item.IsEditing && item.IsFile &&
                    item.DisplayName != null && item.DisplayName.Contains('.'))
                {
                    Dispatcher.Invoke(() =>
                    {
                        var tb = WindowUtilities.FindVisualChild <TextBox>(treeitem);
                        if (tb == null)
                        {
                            return;
                        }
                        var idx = item.DisplayName.IndexOf(".");
                        if (idx > 0)
                        {
                            tb.SelectionStart  = 0;
                            tb.SelectionLength = idx;
                        }
                    }, DispatcherPriority.ApplicationIdle);
                }
            }
        }