Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
WPF:在ListView中展开/折叠项_Wpf_Listview_Expandablelistview - Fatal编程技术网

WPF:在ListView中展开/折叠项

WPF:在ListView中展开/折叠项,wpf,listview,expandablelistview,Wpf,Listview,Expandablelistview,我得到了以下列表视图: 在单击父行的红色按钮时,我希望显示从属行。第二次单击后,行应再次隐藏 我是WPF的新手,不知道1。如何获得可展开/折叠的行和2。如何在父行和子行之间创建关系 我的XAML如下所示: <ListView Name="lvUpgrade"> <ListView.View> <GridView> <GridViewColumn Width="20px">

我得到了以下列表视图:

在单击父行的红色按钮时,我希望显示从属行。第二次单击后,行应再次隐藏

我是WPF的新手,不知道1。如何获得可展开/折叠的行和2。如何在父行和子行之间创建关系

我的XAML如下所示:

<ListView Name="lvUpgrade">
    <ListView.View>
        <GridView>
            <GridViewColumn Width="20px">
                <GridViewColumn.CellTemplate>
                    <DataTemplate>
                        <Image Source="{Binding Path=Icon}" />
                    </DataTemplate>
                </GridViewColumn.CellTemplate>
            </GridViewColumn>
            <GridViewColumn Width="75px" DisplayMemberBinding="{Binding Path=Time, StringFormat={}{0:HH:mm:ss}}" />
            <GridViewColumn Width="300px" Header="Nachricht" DisplayMemberBinding="{Binding Path=Message}" />
        </GridView>
    </ListView.View>
</ListView>

您需要
TreeView
控件

谷歌上提供的“wpf treeview教程”的第一个链接:

您应该使用

检查

作为树视图,是否没有其他可能性?似乎每个节点只能有一个描述。但我想显示每个项目的多个信息。在链接后面的教程中,我找不到符合我需要的类似案例。
ListView
是一个用于显示独立信息集合的视图。没有办法创建层次结构。为此,我们在WPF中有
TreeView
。您可以做什么:创建一个
ItemTemplate
,以特殊方式显示“独立信息”。例子:
Public Class Upgrade

    Public Sub AddMessage(ByVal message As Message)
        Me.lvUpgrade.Items.Add(message)
    End Sub

    Public Class Message

        Public Enum MessageType

            Normal
            Information
            Success
            Warning
            [Error]
        End Enum

        Public Sub New(ByVal type As MessageType, ByVal message As String)
            _Type = type
            _Message = message
        End Sub

        Private _Type As MessageType = MessageType.Normal
        Public ReadOnly Property Type As MessageType
            Get
                Return _Type
            End Get
        End Property

        Private _Message As String = String.Empty
        Public ReadOnly Property Message As String
            Get
                Return _Message
            End Get
        End Property

        Private _Time As DateTime = Now
        Public ReadOnly Property Time As DateTime
            Get
                Return _Time
            End Get
        End Property

        Public ReadOnly Property Icon As BitmapImage
            Get
                Select Case Me.Type
                    Case MessageType.Information
                        Return My.Resources.Information16.ToBitmapImage
                    Case MessageType.Success
                        Return My.Resources.OK16.ToBitmapImage
                    Case MessageType.Warning
                        Return My.Resources.Alert16.ToBitmapImage
                    Case MessageType.Error
                        Return My.Resources.Error16.ToBitmapImage
                    Case Else
                End Select

                Return Nothing
            End Get
        End Property
    End Class
End Class