C# 如何使用mvvm模式在wpf中创建按钮矩阵

C# 如何使用mvvm模式在wpf中创建按钮矩阵,c#,.net,wpf,mvvm,datagrid,C#,.net,Wpf,Mvvm,Datagrid,我需要创建一个看起来像矩阵的数据网格, 每天及其24小时的矩阵显示按钮。 类似于: 7 6 5 4 3 2 1 0 1 . . 23 我使用的MVVM模式似乎使其更难实现, 谢谢大家。诸如此类: <ItemsControl ItemsSource="{Binding DaysOfWeek}"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <UniformGr

我需要创建一个看起来像矩阵的数据网格,
每天及其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
集合(可能是同一个共享集合)


话虽如此,数据驱动的优势是什么?您的矩阵是否可能在维度上发生变化?如果不是,为什么不在你看来对矩阵进行“硬编码”?每个矩阵单元仍然可以绑定到视图模型中的适当数据项。

使用
MVVM
您不会创建接口,而是在UI和数据之间创建链接。你这里有什么问题?我的问题是,我不知道如何在矩阵集合和我的xmal之间连接,以显示我所描述的数据网格。使用
listview
我可以帮你一把。非常感谢。请你给我解释一下,我该如何硬编码。实际上,我更喜欢绑定单元格,而不是视图模型中合适的单元格,我只是不知道怎么做。。。