wpf Listview如何生成子文本

wpf Listview如何生成子文本,wpf,listview,Wpf,Listview,我有一个用项目填充的列表视图,其中一些项目有与之关联的第二行 我想知道是否有一种方法,我可以样式的第二行,所以它可以是一个较小的字体,甚至改变它的颜色 这就是我目前向listview添加内容的方式 listview.Items.Add(New With {Key .name = "First Line" & vbNewLine & "Second Line", .path = path}) 我的Listview XAML <ListView Background="tra

我有一个用项目填充的列表视图,其中一些项目有与之关联的第二行

我想知道是否有一种方法,我可以样式的第二行,所以它可以是一个较小的字体,甚至改变它的颜色

这就是我目前向listview添加内容的方式

listview.Items.Add(New With {Key .name = "First Line" & vbNewLine & "Second Line", .path = path})
我的Listview XAML

<ListView Background="transparent" Margin="10 10 10 10" x:Name="listview" HorizontalAlignment="Stretch" VerticalContentAlignment="center" VerticalAlignment="Stretch" BorderBrush="Transparent">
                    <ListView.View>
                        <GridView>
                            <GridViewColumn Header="name" Width="790" DisplayMemberBinding="{Binding name}" />
                            <GridViewColumn Header="path" Width="0" DisplayMemberBinding="{Binding path}" />
                        </GridView>
                    </ListView.View>

这是一张我现在所拥有的图片,这样你可以看到我在说什么。
我建议为绑定数据创建一个类。用信息填充类并添加到
属性

此线程上的其他评论员建议使用模板。就您的情况而言,
CellTemplate
可能是最佳选择

XAML

<ListView Background="transparent"
      Margin="10 10 10 10"
      x:Name="listview"
      HorizontalAlignment="Stretch"
      VerticalContentAlignment="center"
      VerticalAlignment="Stretch"
      BorderBrush="Transparent">
  <ListView.View>
    <GridView>
      <GridViewColumn Header="name"
                      Width="400"   >
      <GridViewColumn.CellTemplate>
        <DataTemplate>
            <StackPanel Orientation="Vertical">
                    <TextBlock FontSize="25"
                               Text="{Binding FirstLine}" />
                    <TextBlock FontSize="15" Foreground='Orange'
                   Text="{Binding SecondLine}" />
          </StackPanel>
    </DataTemplate>
      </GridViewColumn.CellTemplate>
    </GridViewColumn>
        <GridViewColumn Header="path"   
                        Width="200" 
                        DisplayMemberBinding="{Binding Path}" />
        </GridView>
   </ListView.View>
 </ListView>
屏幕截图

您不应该使用换行符,而应该在项目
子名称中定义一个新属性,然后您可以自定义
项目模板的样式
以显示
子名称的不同样式。您可以使用跑步,但使用BoluI建议的模板会更容易。我已经更新了我的问题。如何使用当前的xaml实现itemtemplate?
 Class MainWindow
   Private Sub MainWindow_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
     For index = 1 To 5
       listview.Items.Add(New BoundDocument With {.FirstLine = index.ToString("D2") & " First Line",
                                                  .SecondLine = "Second Line --" & index.ToString("D2"),
                                                  .Path = "Path " & index})

    Next
 End Sub
End Class

Public Class BoundDocument
    Public Property FirstLine As String
    Public Property SecondLine As String
    Public Property Path As String

End Class