Click here to Skip to main content
15,887,471 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Just a small question but i haven't found an answer to it so far today so i thought i'd just ask myself.

If i place a contentcontrol in my view with it's contents bound to a property, then build a DataGridView in my viewmodel and set that property to it is that breaking MVVM?

Basically my application needs to have a DataGrid that has different columns in different circumstances.

I have read about placing a DataGrid on the view then binding to a columncollection and using behaivours and such.

I felt using a contentcontrol would just be easier really but there must be a reason i can't find many (or any) information on weather that breaks MVVM or not.

What I have tried:

Goole, CodeProject, StackOverflow
Posted
Updated 13-Jun-18 9:36am
Comments
[no name] 13-Jun-18 14:32pm    
Read only?
BeginnerCoderPete 13-Jun-18 14:35pm    
Yes it's a read only DataGrid.

1 solution

Since it's "read-only", it's just a "widget".

It falls in the same category as an "image", "label", chart, "LED".

Treat them all (more or less) as place holders.

In fact, one should be able to swap your "grid" for a "chart" or any other "performance indicator", at any time, without sweating "mvvm".
 
Share this answer
 
Comments
BeginnerCoderPete 14-Jun-18 3:04am    
But how do I change the columns as and when i need to through MVVM? Is what I'm wondering. Should I either build the grid in code and display it in a contentcontrol or place the Grid on my view and bind the columns to a colection?
[no name] 14-Jun-18 12:58pm    
The "grid" itself is a "view": stripped of "logical" elements ("rows"; "columns"), you are left with text blocks, maybe check boxes; i.e. a "view".

So it is a view, or a "view - within - another view".

Bind to it's "own" model; or the "parent" view's model.

In either case "the code behind / model" isn't aware of the "grid" (i.e. "columns").

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900