Click here to Skip to main content
13,836,566 members
Rate this:
Please Sign up or sign in to vote.
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
Updated 13-Jun-18 10:36am
Gerry Schmitz 13-Jun-18 14:32pm
Read only?
BeginnerCoderPete 13-Jun-18 14:35pm
Yes it's a read only DataGrid.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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".
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?
Gerry Schmitz 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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web01 | 2.8.190114.1 | Last Updated 13 Jun 2018
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100