WPF树型视图切换按钮知名度 [英] WPF TreeViewItem Toggle Button visibility

查看:124
本文介绍了WPF树型视图切换按钮知名度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我跑进我希望有人可以帮我解决一个问题。我碰到的在我的节点包含了一组与可见性设置为假子节点的情况。我希望我可以禁用的TreeViewItem旁边的箭头切换,如果所有它的孩子是invisibile。这可能吗?这里有一个例子:

I've ran into an issue I'm hoping someone can help me solve. I've run into a case where my nodes contain a set of child nodes with visibility set to false. I'm hoping that I can disable the toggle arrow beside the TreeViewItem if all it's children are invisibile. Is this possible? Here's an example:

<TreeView Margin="10,10,0,13" Name="TreeView1" HorizontalAlignment="Left" VerticalAlignment="Top" Width="194" Height="200">
    <TreeViewItem Header="Cold Drinks">
        <TreeViewItem Header="Coke" Visibility="False"></TreeViewItem>
        <TreeViewItem Header="Pepsi" Visibility="False"></TreeViewItem>
    </TreeViewItem>
</TreeView>



我将如何得到冷饮的TreeViewItem隐藏切换箭头?

How would i get the Cold Drinks TreeViewItem to hide the toggle arrow?

推荐答案

如果你看到的TreeViewItem的deafult ControlTemplate中,你会看到切换按钮能见度势必ItemsControl.HasItems。触发这个样子的 -

If you see the deafult controlTemplate of TreeViewItem, you will see that visibility of Toggle button is bound to ItemsControl.HasItems. Trigger look like this -

<Trigger Property="ItemsControl.HasItems">
  <Setter TargetName="Expander" Property="UIElement.Visibility" Value="{x:Static Visibility.Hidden}" />
     <Trigger.Value>
        <s:Boolean>False</s:Boolean>
     </Trigger.Value>
</Trigger>



所以,作为一种解决方法,你可以创建自己的自定义控制来自TabItem的来源和绑定你HasItems你自己的CLR属性将通过所有的childItems(TreeViewItems),并返回True如果要是所有的项目都隐藏/折叠状态,任何的项目是可见的或假循环。这样,你的切换按钮会自动将隐藏按触发。

So, as a workaround, you can create your own Custom Control derived from TabItem and bind your HasItems with your own CLR property which will loop through all your childItems(TreeViewItems) and will return True if any of the Item is visible or False if all items are hidden/collapsed state. That way your toggle button will automatically will hide as per Trigger.

如果你想知道如何创建自定义的控制,并将其绑定到CLR属性,你可以参考这 -

In case you want to know how to create Custom control and bind it to your CLR property, you can refer to this -

WPF TreeView控件绑定到隐藏/显示展开/折叠图标

这是有点相同,你一直在寻找的东西。希望这有助于..

This is somewhat same what you has been looking for. Hope this helps..

这篇关于WPF树型视图切换按钮知名度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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