Click here to Skip to main content
15,891,597 members
Home / Discussions / WPF
   

WPF

 
Questionribbon tool bar Pin
transoft18-Oct-11 5:13
transoft18-Oct-11 5:13 
AnswerRe: ribbon tool bar Pin
SledgeHammer0118-Oct-11 5:18
SledgeHammer0118-Oct-11 5:18 
AnswerRe: ribbon tool bar Pin
Alisaunder18-Oct-11 5:38
Alisaunder18-Oct-11 5:38 
QuestionIdentify WPF list conrol Items' Automation ID in QTP Pin
pal2ashish18-Oct-11 2:28
pal2ashish18-Oct-11 2:28 
QuestionAutomationID to WPF controls Pin
pal2ashish14-Oct-11 21:36
pal2ashish14-Oct-11 21:36 
AnswerRe: AutomationID to WPF controls Pin
Abhinav S18-Oct-11 3:32
Abhinav S18-Oct-11 3:32 
GeneralRe: AutomationID to WPF controls Pin
pal2ashish18-Oct-11 19:21
pal2ashish18-Oct-11 19:21 
QuestionMVVM question: hierarchical model representation Pin
Member 103390713-Oct-11 11:06
Member 103390713-Oct-11 11:06 
This one will be easy, I guess.

Suppose I have a model class, for example Day, with its properties. Then I have DayViewModel, which wraps the Day for viewing, presents some other properties which are not present in the model class (like TimeOfSunset which can be computed, whatever, it's an example).
Then I have Week class, which is a collection of Day objects + additional properties. Then again, WeekViewModel which wraps Week for viewing. I am not doing this automatically - one VM class for each M class, I really need to show Days (in a list maybe), hence the DayViewModel, and I want to show and interact with Weeks, hence the WeekViewModel.

Now to the question. The Week class must include some property like List<Day> Days; which will be populated when the Week is loaded from the data store. But WeekViewModel requires something more like ObservableCollection<DayViewModel>. Now this is awkward, I already have one collection and I need to create another with the same physical data, just to change Day to DayViewModel and List to ObservableCollection. I could live with that but it gets worse. Whenever the WeekViewModel's ObservableCollection gets changed, I must take care to change the Week's List accordingly so that when I save the model classes to the data store, I am sure to have the most recent version.

What is the common way to deal with this simple scenario? I believe that one of the benefits of MVVM is the fact, that several ViewModels can work with one Model just like several Views can work with one ViewModel (correct me if I am wrong). Following this principle, I can't simply use ObservableCollection<DayViewModel> directly in the Week (model) class, because that would tie the Model with one particular ViewModel.

So, is there a better way around this than the one I outlined? I'll be happy to hear your suggestions, H.
AnswerRe: MVVM question: hierarchical model representation Pin
Alisaunder14-Oct-11 1:13
Alisaunder14-Oct-11 1:13 
QuestionRe: MVVM question: hierarchical model representation Pin
Member 103390714-Oct-11 3:53
Member 103390714-Oct-11 3:53 
AnswerRe: MVVM question: hierarchical model representation Pin
SledgeHammer0114-Oct-11 5:01
SledgeHammer0114-Oct-11 5:01 
GeneralRe: MVVM question: hierarchical model representation Pin
SledgeHammer0114-Oct-11 5:47
SledgeHammer0114-Oct-11 5:47 
GeneralRe: MVVM question: hierarchical model representation Pin
SledgeHammer0114-Oct-11 6:30
SledgeHammer0114-Oct-11 6:30 
GeneralRe: MVVM question: hierarchical model representation Pin
SledgeHammer0114-Oct-11 8:07
SledgeHammer0114-Oct-11 8:07 
GeneralRe: MVVM question: hierarchical model representation Pin
SledgeHammer0114-Oct-11 8:22
SledgeHammer0114-Oct-11 8:22 
GeneralRe: MVVM question: hierarchical model representation Pin
Member 103390714-Oct-11 8:00
Member 103390714-Oct-11 8:00 
GeneralRe: MVVM question: hierarchical model representation Pin
SledgeHammer0114-Oct-11 8:19
SledgeHammer0114-Oct-11 8:19 
GeneralRe: MVVM question: hierarchical model representation Pin
Member 103390714-Oct-11 9:13
Member 103390714-Oct-11 9:13 
QuestionSetting combobox width by binding Pin
Preston Phillips13-Oct-11 10:30
Preston Phillips13-Oct-11 10:30 
GeneralRe: Setting combobox width by binding Pin
Preston Phillips13-Oct-11 10:51
Preston Phillips13-Oct-11 10:51 
GeneralRe: Setting combobox width by binding Pin
Preston Phillips14-Oct-11 8:37
Preston Phillips14-Oct-11 8:37 
QuestionSet DisplayMemberPath For Dynamic Combobox Pin
Matt Tapia11-Oct-11 8:20
Matt Tapia11-Oct-11 8:20 
AnswerRe: Set DisplayMemberPath For Dynamic Combobox Pin
Wayne Gaylard12-Oct-11 1:09
professionalWayne Gaylard12-Oct-11 1:09 
GeneralRe: Set DisplayMemberPath For Dynamic Combobox Pin
Matt Tapia12-Oct-11 4:19
Matt Tapia12-Oct-11 4:19 
GeneralRe: Set DisplayMemberPath For Dynamic Combobox Pin
Alisaunder13-Oct-11 2:46
Alisaunder13-Oct-11 2:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.