1

I have ContractView. This is to be displayed from 2 separate tiles on my dashboard. One for baseload and one for peak load.

When showing baseload clips the title will be Baseload Clip Definition and when from the Peak Load tile on my dashboard, it will be Peak Load Clip definition

Likewise the ViewModel will need to get Baseload or Peak load clips depending on which tile the user has clicked on

I know one way I could do this is to make 2 separate copies but this seems totally wrong as it would duplicate the views.

On the view model size I am considering creating 2 seperate view models and inheriting them from a ClipDefinitionViewModel. The 2 new view model classes would then know the clip type to obtain from the data service

Is there a better way?

I am using Simple MVVM Toolkit

Paul

Paul
  • 2,773
  • 7
  • 41
  • 96

1 Answers1

0

One class, two objects with different properties.

Have a Title property that you set when the VM is constructed (either pass into the constructor or set explicitly).

Likewise a LoadSource property can define where the VM should look for its definitions.

GazTheDestroyer
  • 20,722
  • 9
  • 70
  • 103
  • ok thanks Gaz, I am using a view model locator via the simple mvvm toolkit so I need to ensure thats possible through that would I not still need 2 XAML files? This kind of leads to a separate question I am about to post though about creating and sharing silverlight controls – Paul Jun 11 '12 at 23:08
  • Ah, ViewModelLocator is using the "view first" pattern (eg you create your view first and then find a viewmodel for it). I guess you would need to XAML files for this then, yes. I've always used ViewModel first which prevents these kind of problems. – GazTheDestroyer Jun 12 '12 at 07:34
  • Is it easy to change? Is there an example you could point me to? I am going to try to get the dashboard into a user control in its own right which will avoid duplication, but am very new to all this so not too sure how to set the property – Paul Jun 12 '12 at 10:11
  • View vs ViewModel first: http://stackoverflow.com/questions/3763072/what-are-the-pros-and-cons-of-view-first-vs-viewmodel-first-in-the-mvvm-pattern. – GazTheDestroyer Jun 12 '12 at 10:41
  • Josh Smith's classic tutorial (ViewModel first): http://msdn.microsoft.com/en-us/magazine/dd419663.aspx – GazTheDestroyer Jun 12 '12 at 10:42