title: WPF MVVM ViewModel constructor designmode
body: <p>I've got a main WPF window:</p>
  
  <pre><code>&lt;Window x:Class="NorthwindInterface.MainWindow"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ViewModels="clr-namespace:NorthwindInterface.ViewModels" Title="MainWindow" Height="350" Width="525"&gt;
      &lt;Window.DataContext&gt;
          &lt;ViewModels:MainViewModel /&gt;
      &lt;/Window.DataContext&gt;
      &lt;ListView ItemsSource="{Binding Path=Customers}"&gt;
  
      &lt;/ListView&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>And the <code>MainViewModel</code> is this:</p>
  
  <pre><code>class MainViewModel : INotifyPropertyChanged
  {
      public event PropertyChangedEventHandler PropertyChanged = delegate { };
  
      public MainViewModel()
      {
          Console.WriteLine("test");
          using (NorthwindEntities northwindEntities = new NorthwindEntities())
          {
              this.Customers = (from c in northwindEntities.Customers
                                select c).ToList();
          }
      }
  
      public List&lt;Customer&gt; Customers { get;private  set; }
  </code></pre>
  
  <p>Now the problem is that in designermode I can't see my <code>MainViewModel</code>, it highlights it saying that it can't create an instance of the <code>MainViewModel</code>. It is connecting to a database. That is why (when I comment the code the problem is solved).</p>
  
  <p>But I don't want that. Any solutions on best practices around this?</p>
  
  <p>And why does this work when working with MVVM:</p>
  
  <pre><code>    /// &lt;summary&gt;
      /// Initializes a new instance of the &lt;see cref="MainViewModel"/&gt; class.
      /// &lt;/summary&gt;
      public MainViewModel()
      {
          // Just providing a default Uri to use here...
          this.Uri = new Uri("http://www.microsoft.com/feeds/msdn/en-us/rss.xml");
          this.LoadFeedCommand = new ActionCommand(() =&gt; this.Feed = Feed.Read(this.Uri), () =&gt; true);
          this.LoadFeedCommand.Execute(null); // Provide default set of behavior
      }
  </code></pre>
  
  <p>It even executes perfectly at design time.</p>