title: How can two view models communicate using catel wpf
body: <p>I read the documentation how can communicate with view models and I try it. But is can't changed. Like the examples from github I create CommunicationViewModel:</p>
  
  <pre><code>public abstract class CommunicationViewModel : ViewModelBase
  {
      public CommunicationViewModel()
      {
          ExampleCommand = new Command(OnExampleCommandExecute);
      }
  
      public string Property
      {
          get { return GetValue&lt;string&gt;(PropertyProperty); }
          set { SetValue(PropertyProperty, value); }
      }
      public static readonly PropertyData PropertyProperty = RegisterProperty("Property", typeof(string), null);
  
      public void UpdateProperty(string modifier)
      {
          Property = modifier.ToString();
      }
  
      public Command ExampleCommand { get; private set; }
  
      private void OnExampleCommandExecute()
      {
          ExecuteCommand();
      }
  
      protected abstract void ExecuteCommand();
  
      protected void AddPropertyChange(string propertyName, Type senderType)
      {
          Argument.IsNotNull(() =&gt; propertyName);
          Argument.IsNotNull(() =&gt; senderType);
          // do some stuff
      }
  }
  </code></pre>
  
  <p>Then from OpenViewModel I want to send information to MainWindowViewModel.</p>
  
  <p>The OpenViewModel Source code:</p>
  
  <pre><code>public class OpenViewModel : CommunicationViewModel
  {
      private readonly IMessageService iMessage;
      private readonly IPleaseWaitService iPleaseWait;
      private readonly ILanguageService iLanguage;
  
      public OpenViewModel(IMessageService iMessageService, IPleaseWaitService iPleaseWaitService, ILanguageService iLanguageService)
      {
          Argument.IsNotNull(() =&gt; iMessageService);
          Argument.IsNotNull(() =&gt; iPleaseWaitService);
          Argument.IsNotNull(() =&gt; iLanguageService);
  
          iMessage = iMessageService;
          iPleaseWait = iPleaseWaitService;
          iLanguage = iLanguageService;
  
          ChooseDatabaseForOpen = new Command(HandleChooseDatabaseForOpen);
      }
  
      public ObservableCollection&lt;string&gt; Databases
      {
          get { return new ObservableCollection&lt;string&gt;(SettingGenerator.ReadFewSameDatabaseSettings("Databases", "Database", "Value")); }
          set { SetValue(DatabasesProperty, value); }
      }        
      public static readonly PropertyData DatabasesProperty = RegisterProperty("Databases", typeof(ObservableCollection&lt;string&gt;), () =&gt; new ObservableCollection&lt;string&gt;());
  
      public Command ChooseDatabaseForOpen { get; private set; }
  
      protected override async Task InitializeAsync()
      {
          await base.InitializeAsync();
          // TODO: subscribe to events here
      }
  
      protected override async Task CloseAsync()
      {
          // TODO: unsubscribe from events here
          await base.CloseAsync();
      }
  
      private void HandleChooseDatabaseForOpen()
      {
          iPleaseWait.Show(iLanguage.GetString("PleaseWaitMessage"));
          SettingGenerator.ChangeDatabaseSetting(null, "ActiveDatabase", this.Database);
          iPleaseWait.Hide();
      }
  
      protected override void ExecuteCommand()
      {
          // InterestedIn does not required any custom logic
      }
  }
  </code></pre>
  
  <p>And the MainWindowViewModel</p>
  
  <pre><code>[InterestedIn(typeof(OpenViewModel))]
  public class MainWindowViewModel : CommunicationViewModel
  {
      private const string PATH_TO_CHECKED_IMAGE = @"./../Resources/Images/Icons/Settings/Checked Checkbox.png";
      private const string PATH_TO_UNCHECKED_IMAGE = @"./../Resources/Images/Icons/Settings/Checkbox.png";
  
      private readonly IUIVisualizerService iUIVisualizer;
      private readonly IPleaseWaitService iPleaseWait;
      private readonly IMessageService iMessage;
      private readonly IOpenFileService iOpenFile;
      private readonly ILanguageService iLanguage;
      private readonly ISplashScreenService iSplashScreen;
  
      private readonly string settingFile = AppDomain.CurrentDomain.BaseDirectory + FileConstants.PATH_TO_SETTINGS_FILE;
  
      public MainWindowViewModel(IUIVisualizerService iUIVisualizerService, IPleaseWaitService iPleaseWaitService, IMessageService iMessageService, IOpenFileService iOpenFileService, ILanguageService iLanguageService, ISplashScreenService iSplashScreenService)
      {
          Argument.IsNotNull(() =&gt; iOpenFileService);
          Argument.IsNotNull(() =&gt; iUIVisualizerService);
          Argument.IsNotNull(() =&gt; iMessageService);
          Argument.IsNotNull(() =&gt; iPleaseWaitService);
          Argument.IsNotNull(() =&gt; iLanguageService);
          Argument.IsNotNull(() =&gt; iSplashScreenService);
  
          this.iOpenFile = iOpenFileService;
          this.iUIVisualizer = iUIVisualizerService;
          this.iMessage = iMessageService;
          this.iPleaseWait = iPleaseWaitService;
          this.iLanguage = iLanguageService;
          this.iSplashScreen = iSplashScreenService;
  
          Minimize = new Command(HandleMinimizeCommand);
          Restore = new Command(HandleRestoreCommand);
          CloseApplication = new Command(HandleCloseApplicationCommand);
  
          if (SettingGenerator.ReadDatabaseSetting(null, "Update") == "Automatic")
          {
              this.AutoUpgradeCheckbox = PATH_TO_CHECKED_IMAGE;
          }
          else if (SettingGenerator.ReadDatabaseSetting(null, "Update") == "Manual")
          {
              this.AutoUpgradeCheckbox = PATH_TO_UNCHECKED_IMAGE;
          }
  
          SelectIconForMainMenuItems();
  
          //this.Property = this.Database;
      }
  
      protected override void OnViewModelPropertyChanged(IViewModel viewModel, string propertyName)
      {
          AddPropertyChange(propertyName, viewModel.GetType());
      }
  
      protected override void ExecuteCommand()
      {
          // InterestedIn does not required any custom logic
      }
  }
  </code></pre>
  
  <p>And from xaml</p>
  
  <p>The OpenView</p>
  
  <pre><code>&lt;ListView Name="DatabasesListView" MinHeight="150" Width="200" ItemsSource="{Binding Databases}" SelectedItem="{Binding Property}" /&gt;
  </code></pre>
  
  <p>The MainWindowView</p>
  
  <pre><code>&lt;Label Content="{Binding Property}" HorizontalAlignment="Center" Margin="0 0 0 0" FontSize="14" /&gt;
  </code></pre>
  
  <p>How can communicate this two view models. In example is working in my case is not working. When I change <code>Property</code> everytime is <code>null</code>. Is not give me some exception just everytime is null.</p>
  
  <p><strong>EDIT:</strong> I used two DataWindows, not using UserControls</p>