title: WPF ReadOnly Dependency Properties using MVVM
body: <p>I've recently overridden the DevXpress WPF grid to give myself a SelectedObject property that I can access from my loosely bound ViewModel.</p>
  
  <p>I've made a SelectedObject dependency property and have it bound OneWayToSource in my XAML.</p>
  
  <p>Everthing works fine, but if I try to make it ReadOnly (for completeness) I get a compile error and says I can't bind to a ReadOnly property. The code below compiles, I've included (but rem'd out) the bits I've been trying in my attempts to get the property ReadOnly.</p>
  
  <p>Can anyone assist please?</p>
  
  <p>The Dependency Property of my overridden control looks like:</p>
  
  <pre><code>  //public static readonly DependencyPropertyKey SelectedRowKey = DependencyProperty.RegisterReadOnly("SelectedObject", typeof(object), typeof(MyGrid), new PropertyMetadata(null));
  //public static readonly DependencyProperty SelectedObjectProperty = SelectedRowKey.DependencyProperty;
  
  public readonly static DependencyProperty SelectedObjectProperty = DependencyProperty.Register("SelectedObject", typeof(object), typeof(MyGrid), new PropertyMetadata(null));
  
  public object SelectedObject
  {
      get
      {
  
          return GetValue(SelectedObjectProperty);
      }
      set
      {
          throw new NotImplementedException();
      }
  }
  </code></pre>
  
  <p>The XAML is:</p>
  
  <pre><code> &lt;StackPanel&gt;
    &lt;devxgrid:MyGrid AutoPopulateColumns="True" DataSource="{Binding Animals}" SelectedObject="{Binding MyObject, Mode=OneWayToSource}" Width="300" Height="300"&gt;
      &lt;devxgrid:MyGrid.View&gt;
          &lt;MyGrid:TableView AllowEditing="False" Name="GridView" AutoWidth="True" /&gt;
      &lt;/devxgrid:MyGrid.View&gt;
   &lt;/devxgrid:MyGrid&gt;
  &lt;/StackPanel&gt;
  </code></pre>