title: MVVM, DataObjects in Catel "best practies"
body: <p>I'm using Catel in my application. I have any questions regarding DataObjects and ViewModels - what is the best way to use Catel efficientlu?</p>
  
  <p>Scenario 1:</p>
  
  <p>I have a MainViewModel and a MainView. In this View I call another View (DataWindow) with a own ViewModel (SettingsViewModel) and show it in a Dialog. In this Dialog I insert some SettingsValues and store it in xml. Last but not least I have a DataObject class to store the data from the Dialog. Here any pseudocode:</p>
  
  <pre><code>MainViewModel : ViewModelBase
  {
          private void OnSystemSettingsCommandExecute()
          {
              //create a new ViewModel and show as Dialog
              uiVisualizerService.ShowDialog(new SystemSettingsViewModel());
          }
  
      ...
  }
  
  SystemSettingsViewModel : ViewModelBase
  {
          /// &lt;summary&gt;
          /// Gets or sets the property value.
          /// &lt;/summary&gt;
          [Model]
          public SettingsDataObject SettingsData
          {
              get { return GetValue&lt;SettingsDataObject&gt;(SettingsDataProperty); }
              set { SetValue(SettingsDataProperty, value); }
          }
  
          /// &lt;summary&gt;
          ///
          /// &lt;/summary&gt;
          public static readonly PropertyData SettingsDataProperty =   RegisterProperty("SettingsData", typeof(SettingsDataObject));
  
  
         /// &lt;summary&gt;
          /// It is right to define the property again here?
          /// &lt;/summary&gt;
          [ViewModelToModel("SettingsData")]
          public string UserName
          {
              get { return GetValue&lt;string&gt;(UserNameProperty); }
              set { SetValue(UserNameProperty, value); }
          }
  
          /// &lt;summary&gt;
          /// Register the UserName property so it is known in the class.
          /// &lt;/summary&gt;
          public static readonly PropertyData UserNameProperty = RegisterProperty("UserName", typeof(string));
  
  
          // Load and Save right here?
          protected override bool Save()
          {
              SettingsData.Save(@"D:\Projects\Testdata\xml\Settings.xml");
  
              return true;
          }
  
          protected override void Initialize()
          {
              SettingsData = SavableModelBase&lt;SettingsDataObject&gt;.Load(@"D:\Projects\Testdata\xml\Settings.xml", SerializationMode.Xml);  
          }
  }
  
  
   public class SettingsDataObject : SavableModelBase&lt;SettingsDataObject&gt;
   {
          // Propertys 
          /// &lt;summary&gt;
          /// Gets or sets the property value.
          /// &lt;/summary&gt;
          public string UserName
          {
              get { return GetValue&lt;string&gt;(UserNameProperty); }
              set { SetValue(UserNameProperty, value); }
          }
  
          /// &lt;summary&gt;
          /// Register the UserName property so it is known in the class.
          /// &lt;/summary&gt;
          public static readonly PropertyData UserNameProperty = RegisterProperty("UserName", typeof(string), "MyUserName");
   }
  </code></pre>
  
  <ol>
  <li>Is it right that I must define the property "UserName" in the DataClass and in the ViewModel class? Is that the "normal way" that I define my Model property in the ViewModel and than i access my data propertys with [ViewModelToModel("SettingsData")]?</li>
  <li>How I can Load and Save automatic my Data Objects? In my case I override the "Save" and the "Initialize" methode? Is there a better way to do this in Catel?</li>
  <li>Now I must have access of the SettingsDataObject in the MainViewModel but i didn't find a way to use the object in other ViewModels. What is the "best practices" to load the settings in other ViewModels? </li>
  </ol>