WPF如何在TreeView上始终显示扩展器

时间:2016-02-17 23:53:52

标签: wpf mvvm treeview

无论节点是否有项目,我都希望始终显示扩展器(用于展开/折叠的三角形)树视图节点。 有没有办法在WPF中执行此操作? 感谢

1 个答案:

答案 0 :(得分:3)

您需要通过提供类似此

的新列表视图样式来覆盖Listview ControlTemplate
Resource Dictionary (WPF)

如果将此文本粘贴到新的 <!--<Trigger Property="HasItems" Value="false"> <Setter TargetName="Expander" Property="Visibility" Value="Hidden"/> </Trigger>--> 文件中,您将看到以下部分已注释掉,无论子项是否存在,都会使扩展器始终存在。

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApplication1"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525">
    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary  Source="resoureces/Dictionary1.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Window.Resources>
    <Grid>
        <TreeView Name="tvBubba">
            <TreeViewItem Header="Top1">
                <TreeViewItem Header="T1-L2" />
            </TreeViewItem>
            <TreeViewItem Header="Top2">

            </TreeViewItem>
        </TreeView>
    </Grid>

</Window>

这是我使用此ResourceDictionary的XAML

nil
相关问题