[英]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.