title: Binding Datasource View to Datagrid in WPF
body: <p>I am trying to get my data to show in a DataGrid.  I am using SQL Server 2012 and Visual Studio 2010 and working with a WPF application.</p>
  
  <p>I created a new datasource, I chose a "View" that I created in SQL Server.  I selected the dropdown on that View in the data pane.  I chose the dropdown and clicked on DataGrid.  Then I dragged it to a user control.  When I run the application, the headers show but the result set does not.  When I run the view in SQL server it returns a result set.  What am I doing wrong?</p>
  
  <p>This is the XAML in the User Control</p>
  
  <pre><code>    &lt;UserControl.Resources&gt;
      &lt;CollectionViewSource x:Key="myviewsViewSource" d:DesignSource="{d:DesignInstance my:myview, CreateList=True}" /&gt;
  &lt;/UserControl.Resources&gt;
  &lt;Grid DataContext="{StaticResource myviewsViewSource}"&gt;
      &lt;DataGrid AutoGenerateColumns="False" EnableRowVirtualization="True" Height="200" HorizontalAlignment="Left" ItemsSource="{Binding}" Margin="561,121,0,0" Name="myviewsDataGrid" RowDetailsVisibilityMode="VisibleWhenSelected" VerticalAlignment="Top" Width="400"&gt;
          &lt;DataGrid.Columns&gt;
              &lt;DataGridTextColumn x:Name="mnemonicColumn" Binding="{Binding Path=Mnemonic}" Header="Mnemonic" Width="SizeToHeader" /&gt;
              &lt;DataGridTextColumn x:Name="nameColumn" Binding="{Binding Path=Name}" Header="Name" Width="SizeToHeader" /&gt;
              &lt;DataGridTextColumn x:Name="toolColumn" Binding="{Binding Path=Tool}" Header="Tool" Width="SizeToHeader" /&gt;
              &lt;DataGridTextColumn x:Name="filterColumn" Binding="{Binding Path=Filter}" Header="Filter" Width="SizeToHeader" /&gt;
              &lt;DataGridTemplateColumn x:Name="createdColumn" Header="Created" Width="SizeToHeader"&gt;
                  &lt;DataGridTemplateColumn.CellTemplate&gt;
                      &lt;DataTemplate&gt;
                          &lt;DatePicker SelectedDate="{Binding Path=Created, Mode=TwoWay, ValidatesOnExceptions=true, NotifyOnValidationError=true}" /&gt;
                      &lt;/DataTemplate&gt;
                  &lt;/DataGridTemplateColumn.CellTemplate&gt;
              &lt;/DataGridTemplateColumn&gt;
              &lt;DataGridTextColumn x:Name="typeColumn" Binding="{Binding Path=Type}" Header="Type" Width="SizeToHeader" /&gt;
          &lt;/DataGrid.Columns&gt;
      &lt;/DataGrid&gt;
  &lt;/Grid&gt;        
  </code></pre>
  
  <p>Here is my C# code:</p>
  
  <pre><code>    public partial class ScanControl : UserControl
  {
      public ScanControl()
      {
          InitializeComponent();
      }       
  
      private void UserControl_Loaded_1(object sender, RoutedEventArgs e)
      {
          if (!System.ComponentModel.DesignerProperties.GetIsInDesignMode(this))
          {
              //Load your data here and assign the result to the CollectionViewSource.
              System.Windows.Data.CollectionViewSource myCollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["myviewsViewSource"];
          }
      }
  }        
  </code></pre>