[英]How to create a button matrix in wpf with mvvm pattern
我需要创建一个看起来像矩阵的数据网格,
矩阵显示每天及其24小时的按钮。
像这样的东西:
7 6 5 4 3 2 1
0
1个
。
。
23
我正在使用MVVM模式,该模式似乎很难实现,
谢谢你们。
像这样:
<ItemsControl ItemsSource="{Binding DaysOfWeek}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Rows="1"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<ItemsControl ItemsSource="{Binding HoursInDay}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Columns="1"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
假设您在数据上下文中(即在主视图模型中)有一个名为DaysOfWeek
的集合。 每个DayOfWeek
对象都会公开HoursInDay
集合(可能是相同的共享集合)。
说了这么多,数据驱动这有什么好处? 您的矩阵尺寸可能会改变吗? 如果没有,为什么不只是在视图中“硬编码”矩阵? 每个矩阵单元仍可以绑定到视图模型中的适当数据项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.