您可以每天只使用ListBox,或者甚至只使用ItemsControl,并且拥有任意数量的它们......您只需要正确地构造您的数据。假设您有一个 Day 类,其中包含一个 Date 和一个名为 Tasks 的集合:
public class Day // Implement INotifyPropertyChanged correctly here
{
public DateTime Day { get; set; }
public ObservableCollection<string> Tasks { get; set; }
}
现在在您的视图模型中,您只需要Day 实例的集合:
public ObservableCollection<Day> Days { get; set; }
那么你只需要一个DataTemplate 来为每个Day 实例定义你的ListBox:
<DataTemplate DataType="{x:Type DataTypes:Day}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Text="{Binding Date, StringFormat={}{0:MMM d}}" />
<ListBox Grid.Row="1" ItemsSource="{Binding Tasks}" />
</Grid>
</DataTemplate>
最后,添加ListBox 或ItemsControl 以显示Days 的集合并将ItemsPanel 设置为StackPanel,并将其Orientation 属性设置为Horizontal:
<ItemsControl DockPanel.Dock="Top" ItemsSource="{Binding Days}" Name="overlayItems">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
添加一些测试数据和你的离开:
Days = new ObservableCollection<Day>();
Days.Add(new Day() { Date = new DateTime(2014, 5, 1), Tasks = new ObservableCollection<string>() { "Doing something today", "Doing something else today" } });
Days.Add(new Day() { Date = new DateTime(2014, 5, 2), Tasks = new ObservableCollection<string>() { "Doing nothing today" } });
Days.Add(new Day() { Date = new DateTime(2014, 5, 3), Tasks = new ObservableCollection<string>() { "Doing something today" } });
我会把更详细的信息留给你。