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/