WPF树视图项目设为只读

编程入门 行业动态 更新时间:2024-10-07 08:31:57
本文介绍了WPF树视图项目设为只读的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想知道如何在WPF中读取树视图项.那里是只读属性吗? 我有一个展开的Treeview,我想让用户不允许折叠它.我该怎么做. < treeview> < treeview.itemcontainerstyle> < Style TargetType ="TreeViewItem"> < setter property ="IsSelected" value ="false"> </Style> 我在Xaml中使用了它,但仍然允许将其折叠. 请帮我. 谢谢&问候 Monish K.M

Hi, I would like to know that how Tree View Items get read only in WPF. Is read only property there? I have a Treeview which is expanded and I want to make user not allow to collapse it.How I do it. <treeview> <treeview.itemcontainerstyle> <Style TargetType="TreeViewItem"> <setter property="IsSelected" value="false"> </Style> I used this in Xaml.But still allow to collapse it. Please help me. Thanks & Regards Monish K.M

推荐答案

否.如果您指的是类System.Windows.Controls.TreeViewItem,则它没有类似的内容,请亲自查看: msdn.microsoft/en-us/library/system.windows.controls.treeviewitem%28v=vs.95%29.aspx [ ^ ]. 这样做的原因并不简单,而是非常简单:整个控件System.Windows.Controls.TreeView在以下意义上已经完全是只读的:没有预定义的修改操作可以立即进行.除非您在代码中定义,否则通过UI使用.此外,之所以这样,是因为该控件不包含任何预定义的数据对象,除非开发人员定义了它们.只有在代码中定义了编辑模式"(就地编辑)或通过UI进行的其他数据修改操作(添加/删除/编辑节点)之类的任何操作,才有可能.如果这样做,您将能够定义自己的只读或类似概念.请参阅: msdn.microsoft/zh-cn/library/system.windows.controls.treeview%28v = vs.95%29.aspx [ ^ ].
—SA
No. If you mean the class System.Windows.Controls.TreeViewItem, it does not have anything like that, please see by yourself: msdn.microsoft/en-us/library/system.windows.controls.treeviewitem%28v=vs.95%29.aspx[^]. The reason for this is not simple, but very simple, thing about it: the whole control System.Windows.Controls.TreeView is already totally read-only in the following sense: there are no predefined modifying operations which could be immediately used via UI, unless you define this in your code. Moreover, this is so because this control does not contain any predefined data object, unless the developer defines them. Anything like "edit mode" (in-place editing) or other data modification operations (add/remove/edit a node) via UI are possible only if you defined them in your code. If you do, you will be able to define your own notion of read-only or anything like that. Please see: msdn.microsoft/en-us/library/system.windows.controls.treeview%28v=vs.95%29.aspx[^].
—SA

如果使用MVVM模式,则可以绑定到IsExpanded,并始终返回true.如此使用TreeViewItem上的Collapsed 事件来迫使该项目重新展开的另一种可能性. If you use the MVVM pattern, you can bind to the IsExpanded, and always return true. The other possiblility to so used the Collapsed event on the TreeViewItem to force the item back to expanded.

此帮助吗? Does this help: <TreeView> <TreeView.ItemContainerStyle> <Style TargetType="TreeViewItem"> <Setter Property="IsSelected" Value="false"/> </Style> </TreeView.ItemContainerStyle> </TreeView>

这将使您的树形视图项目无法选择.

This will make your treeview items not selectable.

更多推荐

WPF树视图项目设为只读

本文发布于:2023-11-12 20:50:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1582501.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:设为   视图   项目   WPF

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!