c# - 双击可编辑的 TreeViewItem

标签 c# wpf treeview treeviewitem

 private void SetCurrentItemInEditMode(bool EditMode)
 {
        if (product_tree.SelectedItem is TreeViewItem)
        {
            TreeViewItem tvi = product_tree.SelectedItem as TreeViewItem;
            // Also make sure that the TreeViewItem
            // uses an EditableTextBlock as its header
            if (tvi.Header is EditableTextBlock)
            {
                EditableTextBlock etb = tvi.Header as EditableTextBlock;

                // Finally make sure that we are
                // allowed to edit the TextBlock
                if (etb.IsEditable)
                    etb.IsInEditMode = EditMode;
            }
        }
    }


error: The type or namespace name 'EditableTextBlock' could not be found (are you missing a using directive or an assembly reference?)  

我正在 WPF 应用程序中创建一个 TreeView。 TreeViewItem 是从数据库中获取的,当我双击 TreeViewItem 时,我想制作可编辑的 treeviewitem。但我收到了这个错误。我搜索了这个错误,但找不到任何好的解决方案

最佳答案

在我看来,您从其他地方复制了一些代码。 TreeView 在 WPF 中不可编辑。您复制了一些代码,但找不到类 EditableTextBlock,因为它不存在于 PresentationFramework 中,并且您没有添加您复制的文章中引用的组件。通常,当您没有添加程序集引用和/或 using 语句来包含错误所指的类时,您会收到此编译时错误。

我想将它成功地包含在您的项目中的第一步是了解它在您从中复制它的项目中是如何工作的。

关于c# - 双击可编辑的 TreeViewItem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24030598/

相关文章:

c# - WPF MVVM 将项目添加到组合框并更改选定项目

.net - 将上下文菜单命令参数绑定(bind)到数据网格属性

c# - String 中的 ImageSource 不起作用?

css - JavaFX2 : What is the best way to style an individual TreeItem?

c# - 当出现 "Padding is invalid and cannot be removed"错误时,如何将 C++ Rijndael 密码学转换为 C#?

c# - 具有完全不相关的静态方法的静态类有什么问题吗?

c# - 如何获取应用程序的事件 ChildWindow?

c# - 如何使用 XAML 将事件绑定(bind)到成员字段或属性的事件处理程序?

c# - Windows 窗体/ TreeView : How do I put CheckBoxes only on the leaves?

wpf - 如何强制 ItemContainerGenerator 为项目生成容器或如何在启用 UI 虚拟化时将 TreeView 滚动到展开节点?