title: WPF setting the DataContext through a constructor
body: <p>As I understand it, when I bind my ViewModel to my View, it is done via the DataContext. Something like</p>
  
  <pre><code>   &lt;Grid.Resources&gt;
          &lt;myData:MyVM x:Key="Vm" /&gt;
      &lt;/Grid.Resources&gt;
      &lt;Grid.DataContext&gt;
          &lt;Binding Source="{StaticResource Vm}"&gt;&lt;/Binding&gt;
      &lt;/Grid.DataContext&gt;
  </code></pre>
  
  <p>My understanding of how the ViewModel is populated is the View calls the ViewModel (via binding), and the ViewModel talks to the Model and does what ever it needs to do to get itself (ViewModel) into a desired state.</p>
  
  <p>So, what happens if your "Model" is created by the UI? My model is a parameter on my MainWindow Constructor.</p>
  
  <p>So, my View (MainWindow) is</p>
  
  <pre><code>public MainWindow(MyObject myObject)
      {
            InitializeComponent();
      }
  </code></pre>
  
  <p>My ViewModel is</p>
  
  <pre><code> public class ViewModel 
  {
      #region properties
  
      private MyObject myList;
      public MyObject MyList
      {
          get; set ;
      }
  
      #region Constructors
  
      public ViewModel ()
      {
  
      }
  
      public ViewModel (MyObject myObject)
      {
          this.myObject= myObject;
      }        
  }
  </code></pre>
  
  <p>Now, when my application runs up, (and I'm sure I'm using the wrong words here) how do I  'inject' my parameter into the ViewModel? Or do we feel there is a better approach?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>To explain what I'm trying to achieve may help. My program performs some tasks and creates a log. The log is stored in memory. At the end of my programs processes, the log is shown on screen. This is why I'm passing the object into the constructor.</p>