title: assign itemsSource of DataGrid inside usercontrol in wpf
body: <p>I am quite new to wpf so maybe I am missing something obvious here. I have found a similar question in stackoverflow and tried the solution (which is implemented in the code given below) but was not able to get it work. The link is <a href="https://stackoverflow.com/questions/3904510/how-to-access-itemssource-property-of-a-datagrid-defined-in-usercontrol-from-mai">here</a>. Let me explain the problem. I am working with framework 2010.</p>
  
  <p>I have a usercontrol which contains 1 datagrid and 3 buttons. The xaml of the same is as below.</p>
  
  <pre><code>&lt;UserControl x:Class="RadarControls.RadarDataGrid"
           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
           xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
           xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
           xmlns:diagnostics="clr-namespace:System.Diagnostics;assembly=WindowsBase"
           xmlns:local="clr-namespace:RadarControls"
           mc:Ignorable="d" 
           d:DesignHeight="300" d:DesignWidth="300"&gt;
  &lt;Grid&gt;
      &lt;Grid.ColumnDefinitions&gt;
          &lt;ColumnDefinition /&gt;
          &lt;ColumnDefinition /&gt;
          &lt;ColumnDefinition /&gt;
      &lt;/Grid.ColumnDefinitions&gt;
      &lt;Grid.RowDefinitions&gt;
          &lt;RowDefinition /&gt;
          &lt;RowDefinition Height="25" /&gt;
      &lt;/Grid.RowDefinitions&gt;
  
      &lt;DataGrid Name="myGrid" Grid.ColumnSpan="3" ItemsSource="{Binding}" AutoGenerateColumns="True"&gt;&lt;/DataGrid&gt;
  
      &lt;Button Content="Add" Grid.Row="1" Height="23" Margin="0,2,2,0" HorizontalAlignment="Left" Name="btnAdd" Width="100" /&gt;
      &lt;Button Content="Delete" Grid.Column="1" Grid.Row="1" Margin="0,2,2,0" Height="23" HorizontalAlignment="Left" Name="btnDelete" Width="100" /&gt;
      &lt;Button Content="Save" Grid.Column="2" Grid.Row="1" Height="23" Margin="0,2,0,0" HorizontalAlignment="Left" Name="btnSave" Width="100" /&gt;
  &lt;/Grid&gt;
  &lt;/UserControl&gt;
  </code></pre>
  
  <p>The xaml of my window where i am using this usercontrol is as below</p>
  
  <pre><code>&lt;Window x:Class="RadarStudio.Users"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:ctrls="clr-namespace:RadarControls;assembly=RadarControls"
      xmlns:vm='clr-namespace:RadarViewModel.Users;assembly=RadarViewModel'
      Title="Users" Height="300" Width="300"&gt;
  &lt;Grid &gt;
      &lt;ctrls:RadarDataGrid Name="grid1" DataContext="{Binding str}"&gt;&lt;/ctrls:RadarDataGrid&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p></p>
  
  <p>My window code behind is as follows</p>
  
  <pre class="lang-cs prettyprint-override"><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Windows;
  using System.Windows.Controls;
  using System.Windows.Data;
  using System.Windows.Documents;
  using System.Windows.Input;
  using System.Windows.Media;
  using System.Windows.Media.Imaging;
  using System.Windows.Shapes;
  using System.Collections.ObjectModel;
  
  namespace RadarStudio
  {
      /// &lt;summary&gt;
      /// Interaction logic for Users.xaml
      /// &lt;/summary&gt;
      public partial class Users : Window
      {
          public Users()
          {
              InitializeComponent();
              //this.DataContext = this;
  
              str.Add("dhaval");
              str.Add("ravinder");
          }
  
          public ObservableCollection&lt;string&gt; str = new ObservableCollection&lt;string&gt;();
      }
  }
  </code></pre>
  
  <p>I tried so many things but I am not able to get the strings on my grid. </p>
  
  <p>Please help!
  Thanks in advance!</p>
  
  <p>Regards,</p>
  
  <p>Samar</p>