0

我正在尝试在 listView 中获取多行我目前有以下 XAML:

        <ListView x:Name="listTasks" Margin="0,0,1.5,0" Background="{x:Null}" BorderBrush="{x:Null}" BorderThickness="0" Foreground="White" ItemsSource="{Binding TasksCollection}" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Auto">
        <ListView.ItemContainerStyle>
    <Style TargetType="{x:Type ListViewItem}">
            <Style.Triggers>
                    <Trigger Property="IsSelected"
                                     Value="True">
                            <Setter Property="Background"
                                            Value="{x:Null}" />
                            <Setter Property="BorderBrush"
                                            Value="{x:Null}" />
                    </Trigger>
                    <Trigger Property="IsMouseOver"
                                     Value="True">
                            <Setter Property="Background"
                                            Value="{x:Null}" />
                            <Setter Property="BorderBrush"
                                            Value="{x:Null}" />
                    </Trigger>
            </Style.Triggers>
            <Setter Property="Height" Value="50px" />
            <Setter Property="Focusable" Value="false" />
    </Style>
</ListView.ItemContainerStyle>
        <ListView.Resources>
                <Style x:Key="CustomHeaderStyle" TargetType="{x:Type GridViewColumnHeader}">
                    <Setter Property="Visibility" Value="Collapsed" />
                </Style>
            </ListView.Resources>
            <ListView.View>
                <GridView ColumnHeaderContainerStyle="{DynamicResource CustomHeaderStyle}">
                    <GridViewColumn Header="">
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock>
                                <TextBlock.Text>
                                    <MultiBinding  StringFormat=" Module: {0} Conditions: {1}|{2}|{3} for {4} minutes">
                                        <Binding Path="Module"/>
                                        <Binding Path="FirstValue"/>
                                        <Binding Path="SecondValue"/>
                                        <Binding Path="ThirdValue"/>
                                        <Binding Path="Minutes"/>
                                    </MultiBinding>
                                </TextBlock.Text>
                                </TextBlock>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                </GridView>
            </ListView.View>
        </ListView>

这会输出如下内容:

在此处输入图像描述

我想要实现的是这样的(忽略不同颜色的背景):

在此处输入图像描述

我似乎无法思考如何做到这一点,有什么想法吗?

谢谢

4

1 回答 1

1

您可以使用垂直StackPanel来将一系列TextBlock元素放在另一个之上:

<DataTemplate>
   <StackPanel>
      <TextBlock Text="{Binding Module, StringFormat='Module: {0}'}"/>
      <TextBlock Text="{Binding FirstValue, StringFormat='Module: {0}'}"/>
      ...
   </StackPanel>
</DataTemplate>

或者您可以在一个“TextBlock”中格式化所有内容:

<DataTemplate>
   <TextBlock>
      <Run Text="Module: "/><Run Text="{Binding Module}"/><LineBreak/><Run Text="Conditions: "/><Run Text="{Binding FirstValue}"/><LineBreak/>
      ...
   </TextBlock>
</DataTemplate>
于 2012-05-20T13:27:47.077 回答