[英]Grouping ListBox with Date on same line as Data
我有一個ListBox綁定到一個名為“ Schedules”的ListCollectionView。
<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
-----------------時間| 文字
-----------------時間| 文字
-----------------時間| 文字
MyDateTime2
-----------------時間| 文字
我希望它顯示如下:
MyDateTime | 時間| 文字
| 時間| 文字
| 時間| 文字
MyDateTime | 時間| 文字
| 時間| 文字
| 時間| 文字
將grid.rowspan添加到您的xaml以合並行
<TextBlock Grid.Column="0" Grid.Row="0" Grid.RowSpan="2" Text="{Binding MyDateTime}" HorizontalAlignment="Left" VerticalAlignment="Center"/>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.