0

我有一个绑定到名为“Schedules”的 ListCollectionView 的 ListBox。

<ListBox Grid.Row="2" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ItemsSource="{Binding Schedules}">
    <ListBox.GroupStyle>
        <GroupStyle>
            <GroupStyle.HeaderTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Name}" />
                </DataTemplate>
            </GroupStyle.HeaderTemplate>
        </GroupStyle>
    </ListBox.GroupStyle>
    <ListBox.ItemTemplate>
        <DataTemplate>
            <StackPanel Background="Transparent">
                <Grid Background="Transparent">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition  Width="100"/>
                        <ColumnDefinition  Width="100"/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition/>
                    </Grid.RowDefinitions>
                    <!--I want my DateTime Grouping Here basically-->
                    <!--<TextBlock Grid.Column="0" Grid.Row="0"  Text="{Binding MyDateTime}" HorizontalAlignment="Left"  VerticalAlignment="Center"/>-->
                    <TextBlock Grid.Column="1" Grid.Row="0"  Text="{Binding MyDateTime, StringFormat='t'}" HorizontalAlignment="Left"  VerticalAlignment="Center"/>
                    <TextBlock Grid.Column="2" Grid.Row="0"  Text="{Binding SomeText}"  TextTrimming="WordEllipsis" LineStackingStrategy="MaxHeight" MaxHeight="20" HorizontalAlignment="Left"  VerticalAlignment="Center"/>
                </Grid>
            </StackPanel>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

在我的视图模型中,我只按日期分组(我使用一个 ValueConverter,它只给我一个日期:

Schedules.GroupDescriptions.Add(new PropertyGroupDescription("MyDateTime", new DateTimeToDateOnlyConverter()));

是否可以进行分组但将其显示在与其他数据相同的行上?现在你有一个案例:

MyDateTime
-----------------时间 | Sometext
-----------------时间 | Sometext
-----------------时间 | Sometext
MyDateTime2
-----------------时间 | 一些文本

我希望它像这样显示:

我的日期时间 | 时间 | 一些文字
                     | 时间 | 一些文字
                     | 时间 | Sometext
MyDateTime | 时间 | 一些文字
                     | 时间 | 一些文字
                     | 时间 | 一些文本

4

1 回答 1

0

将 grid.rowspan 添加到您的 xaml 以合并行

<TextBlock Grid.Column="0" Grid.Row="0" Grid.RowSpan="2" Text="{Binding MyDateTime}" HorizontalAlignment="Left" VerticalAlignment="Center"/>

于 2016-12-13T12:27:50.800 回答