title: WPF data context for design time and run time
body: <p>I'm learning WPF, MVVM Light and the ViewModelLocator pattern and running into difficulties with my main window's data context.</p>
  
  <pre><code>public class ViewModelLocator
     {
        public ViewModelLocator()
        {
           var mainModel = new MainModel();
           Main = new MainViewModel(mainModel);
        }
  
        public MainViewModel Main { get; private set; }
  
        public static ViewModelLocator Instance
        {
           get { return Application.Current.Resources["Locator"] as ViewModelLocator; }
        }
     }
  </code></pre>
  
  <p>and in my app.xaml:</p>
  
  <pre><code>&lt;Application.Resources&gt;
      &lt;viewModels:ViewModelLocator x:Key="Locator" /&gt;
  &lt;/Application.Resources&gt;
  </code></pre>
  
  <p>When I set the data context in my main window using:</p>
  
  <pre><code>DataContext="Binding Main, Source={StaticResource Locator}"
  </code></pre>
  
  <p>it compiles but all of MainViewModel's properies I bind to elsewhere in the xaml show up red with tooltip "cannot resolve symbol". I thought I could get around this by also specifying a designer-only data context:</p>
  
  <pre><code>&lt;Window x:Class="WPFDemo.Windows.MainWindow"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
      xmlns:converters="clr-namespace:WPFDemo.Converters"
      xmlns:local="clr-namespace:WPFDemo"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
      xmlns:models="clr-namespace:WPFDemo.Models"
      xmlns:viewModels="clr-namespace:WPFDemo.ViewModels"
      Title="MainWindow" Height="350" Width="525"
      DataContext="Binding Main, Source={StaticResource Locator}"
      mc:Ignorable="d"
      d:DataContext="{d:DesignInstance, Type=viewModels:MainViewModel,
      IsDesignTimeCreatable=True}"&gt;
  </code></pre>
  
  <p>but the compiler doesn't like that last line ("The character ',' is unexpected at this position", referrring to the first comma). Note I'm not using ExpressionBlend, but I thought I heard in a course that this line would enable VisualStudio designer as well:</p>
  
  <pre><code> xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  </code></pre>
  
  <p>How do I use a ViewModelLocator while still enabling Visual Studio to recognize bound properties at design time?</p>