I need to create a datagrid that look like a matrix,
The matrix display buttons for each day and its 24 hours.
somthing like:
7 6 5 4 3 2 1
0
1
.
.
23
I am using MVVM pattern that seems to make it harder to implement,
thank you all.
1 Answer
Something like this:
<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>
This assumes you have a collection called DaysOfWeek in your data context (ie. in your main view model). Each DayOfWeek object would expose an HoursInDay collection (likely the same shared collection).
Having said all that, what is the advantage to data-driving this? Is your matrix likely to change in dimensions? If not, why not just "hard-code" the matrix in your view? Each matrix cell can still bind to an appropriate data item in your view model.
2 Comments
user1606328
Thank you very much. may you explain to me how can i do it hard - coded.
user1606328
Actully i prefer binding cell to an appropriate in my view model, i just dont know how to do that...
MVVMyou do not create an interface, but create link between UI and data. What is you problem here ?listviewI can give you a hand