title: WPF Binding User Controls
body: <p>Ok, so I've created two things, a MainWindowViewModel and a TabControlViewModel. Within my TabControlViewModel my View is basically a TabControl with 3 tabitems (Welcome/tabItem1/tabItem2).</p>
  
  <p>My goal is when the application starts up I see the welcome tab only and then when I select File -> Open both tabItems become visible and the focus shows my tabItem2 displaying the text file content.</p>
  
  <p>MainWindow.Xaml</p>
  
  <pre><code>&lt;Menu DockPanel.Dock="Top" Width="Auto" Height="25" Name="Menu1"&gt;
                  &lt;MenuItem Header="_File" VerticalContentAlignment="Top" &gt;
                      &lt;MenuItem Header="_New" Command="{Binding NewCommand}" /&gt;
                      &lt;MenuItem Header="_Open" Command="{Binding OpenCommand}"&gt;
  </code></pre>
  
  <p>TabControlViewModel.cs</p>
  
  <pre><code>class TabControlViewModel : TabContainer
  {
  
     private DelegateCommand openCommand;
      public ICommand OpenCommand
      {
          get
          {
              if (openCommand == null)
                  openCommand = new DelegateCommand(Open);
              return openCommand;
          }
      }
  
      private void Open(object obj)
      {
          ProcessOpenCommand();
      }
  
      private void ProcessOpenCommand()
      {
          if (dataChanged)
          {
              SaveFirst();
              ShowOpenDialog();
  
          }
          else
          {
              ShowOpenDialog();
  
          }
      }
  
      private void ShowOpenDialog()
      {
          System.Windows.Forms.OpenFileDialog ofd = new System.Windows.Forms.OpenFileDialog();
          ofd.Filter = "Text File (*.txt)|*.txt";
  
          if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
          {
              filePath = ofd.FileName;
              ReadFile(filePath);
              SetTitle(ofd.SafeFileName);
              RuleTab.Focus();
          }
      }
  
      private string SaveFirst()
      {
          MessageBoxResult mbr = System.Windows.MessageBox.Show("Do you want to save changes?", "Save Changes", MessageBoxButton.YesNoCancel, MessageBoxImage.Warning);
  
          if (mbr == MessageBoxResult.Yes)
          {
              if (filePath != null)
              {
                  SaveFile(filePath);
              }
              else
              {
                  ProcessSaveCommand();
              }
          }
          else if (mbr == MessageBoxResult.Cancel)
          {
              return "Cancel";
          }
          return "Nothing";
      }
  </code></pre>
  
  <p>I guess my biggest question is, should my Menu commands be in this TabControlViewModel or in my MainWindowViewModel? Many thanks for your patience here folks...:)</p>