title: Save the text of a RichTextBox
body: <p>I could do this easily in code-behind but don't want to break the <code>MVVM</code> pattern.</p>
  
  <p>I have a <code>RichTextBox</code> and a 'Save' Button in my View. I want to save the contents of the RichTextBox to a file on the Save button click.</p>
  
  <p>I have written a delegate class which expects a method to return void and have a single object parameter. I did this because I couldn't use the System.Action delegate.</p>
  
  <pre><code>class BtnCommandParameterised : ICommand
  {
      public delegate void ActionParameterised(object rtb);
  
      private ActionParameterised _actionParameterised;
      public object _object;
  
  
      public BtnCommandParameterised(ActionParameterised   BtnCommandParameterisedActionParameterised)                      
      {
          _actionParameterised = BtnCommandParameterisedActionParameterised;
      }
  
      public bool CanExecute(object parameter)
      {
          return true;
      }
  
      public void Execute(object parameter)
      {
          _actionParameterised.Invoke(_object);
      }
  
      public event EventHandler CanExecuteChanged;
  }
  </code></pre>
  
  <p>Then in my ViewModel I have an <code>InitialiseBtnCommands()</code> method which is called from the constructor. This initializes the command:</p>
  
  <pre><code>  private void InitialiseBtnCommands()
      {
          ReturnTextAsStringCommand = new      BtnCommandParameterised(ReturnTextAsStringCommandAction);
      }
  </code></pre>
  
  <p>This invokes my method to save the file.</p>
  
  <pre><code> private void ReturnTextAsStringCommandAction(object Document)
      {
          TextRange range;
          FileStream fileStream;
  
          range = new TextRange(((FlowDocument)Document).ContentStart,
                                ((FlowDocument)Document).ContentEnd);
  
          fileStream = new FileStream(FileName, FileMode.Create);
          range.Save(fileStream, DataFormats.Text);
          fileStream.Close();
          Xceed.Wpf.Toolkit.MessageBox.Show("Text File Saved");
      }
  </code></pre>
  
  <p>Finally, in the View XAML, this is my binding:</p>
  
  <pre><code>  &lt;Grid Name="MainGrid" DataContext="{StaticResource EditorViewModel}"&gt;
      &lt;xctk:RichTextBox  SpellCheck.IsEnabled="True" HorizontalAlignment="Center"  Margin="206,166,206,60" Name="richTextBoxArticleBody" AcceptsTab="True" BorderBrush="Silver" BorderThickness="1" VerticalAlignment="Center"  Height="306" Width="600" FontFamily="Arial"/&gt;
      &lt;Button Command="{Binding ReturnTextAsStringCommand}" CommandParameter="{Binding ElementName=richTextBoxArticleBody, Path=Document}" Content="Save Article Text" Height="23" HorizontalAlignment="Left" Margin="703,478,0,0" Name="button1" VerticalAlignment="Top" Width="103" /&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p>The command is being called and my method is invoked but nothing is passed into the <code>ReturnTextAsStringCommandAction</code> method?</p>
  
  <p>I'm new to MVVM, finding things shall we say, a little confusing.</p>