0

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.

3
  • with MVVM you do not create an interface, but create link between UI and data. What is you problem here ? Commented Sep 16, 2012 at 7:11
  • My problem is that I dont know how to connect between a matrix collection and my xmal to present a datagrid as i described. Commented Sep 16, 2012 at 7:34
  • with listview I can give you a hand Commented Sep 16, 2012 at 8:06

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you very much. may you explain to me how can i do it hard - coded.
Actully i prefer binding cell to an appropriate in my view model, i just dont know how to do that...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.