WPF树视图项目设为只读 [英] WPF Tree View items make read only

查看:90
本文介绍了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,则它没有类似的内容,请亲自查看: ^ ].

这样做的原因并不简单,而是非常简单:整个控件System.Windows.Controls.TreeView在以下意义上已经完全是只读的:没有预定义的修改操作可以立即进行.除非您在代码中定义,否则通过UI使用.此外,之所以这样,是因为该控件不包含任何预定义的数据对象,除非开发人员定义了它们.只有在代码中定义了编辑模式"(就地编辑)或通过UI进行的其他数据修改操作(添加/删除/编辑节点)之类的任何操作,才有可能.如果这样做,您将能够定义自己的只读或类似概念.请参阅:
http://msdn.microsoft.com/zh-cn/library/system.windows.controls.treeview%28v = vs.95%29.aspx [
No. If you mean the class System.Windows.Controls.TreeViewItem, it does not have anything like that, please see by yourself: http://msdn.microsoft.com/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:
http://msdn.microsoft.com/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树视图项目设为只读的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆