title: WPF SelectedItem property in nested DataGrid in UserControl
body: <p>I have <code>UserControl</code>, lets call it as <code>CustomDataGrid</code>, that contains <code>DataGrid</code>. Remained content doesn't matter. <code>SelectedItem</code> property of <code>DataGrid</code> must be <code>SelectedItem</code> property of <code>CustomDataGrid</code>. And I wanna be able to use <code>Binding</code> with this property, cause I use <code>MVVM</code> pattern. So I have to declare <code>SelectedItem</code> as <code>DependencyProperty</code> in <code>CustomDataGrid</code>. But I have no ideas haw can I make it properly...</p>
  
  <p>This is how <code>DepedencyProperty</code>-s is declared usually:</p>
  
  <pre><code>public static readonly DependencyProperty SelectedItemProperty = DependencyProperty.Register(
          "SelectedItem", typeof(Object), typeof(CustomDataGrid),
          new FrameworkPropertyMetadata(default(Object), SelectedItemPropertyCallback)
          {
              BindsTwoWayByDefault = true, 
              DefaultUpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
          });
  
  // Optionally
  private static void SelectedItemPropertyCallback(DependencyObject obj, DependencyPropertyChangedEventArgs e)
  {
      // dataGrid - `DataGrid` nested in `UserControl` 
      ((CustomDataGrid)obj).dataGrid.SelectedItem = e.NewValue;
  }
  
  // Obviously, it has no any link with nested `dataGrid`. This is the problem.  
  public Object SelectedItem
  {
  
      get { return GetValue(SelectedItemProperty); }
      set { SetValue(SelectedItemProperty, value); }
  }
  </code></pre>
  
  <p>So, how can I declare <code>SelectedItem</code> property correctly? </p>