1

What is the best way to add user defined data to a ViewModel at design time?

At runtime I want to display a subset of ViewModels for a class that don't require a root element. To do this at the moment I am tagging the ViewModels at design time by creating a ViewModel variable and assign it an intialvalue and using it as follows:

   ViewModelUserControl vmc = new ViewModelUserControl();
   vmc.ViewModelName = name;
   vmc.SetEcoSpace(ecoSpace);
   string vmTitle = vmc.ViewModel.ViewModelVariables
               .Find(x =>x.Name=="vmUserTitle")?.InitialValue ?? "";
   if (vmTitle != "")
   {
        ...display and do stuff with the ViewModel...

Is there a better way?

Steve.Au
  • 31
  • 5

1 Answers1

1

ViewModels can have TaggedValues, on all levels. I would use that instead of a variable defintion.

Hans Karlsen
  • 2,275
  • 1
  • 15
  • 15