title: DataGridTextColumn - How to bind IsReadonly?
body: <p>In Silverlight 4, the IsReadOnly property of DataGridTextColumn seems to be no dependency property. Hence I could not bind it to a property on the viewmodel.</p>
  
  <p>It seems the only alternative is using a DataTemplate, but even here I am facing two major problems:</p>
  
  <pre><code>&lt;sdk:DataGrid Style="{StaticResource DataGridStyle}" x:Name="call_dataGrid" ItemsSource="{Binding Calls}"&gt;
                      &lt;sdk:DataGrid.Columns&gt;
                          &lt;sdk:DataGridTextColumn Header="Call Time" Binding="{Binding Path=CallTime}" /&gt;
                          &lt;sdk:DataGridTemplateColumn Header="Call Date"&gt;
                              &lt;sdk:DataGridTemplateColumn.CellEditingTemplate&gt;
                                  &lt;DataTemplate&gt;
                                      &lt;TextBox Text="{Binding Path=CallDate}" IsReadOnly="{Binding Path=DataContext.IsInEditMode, ElementName=call_dataGrid, Converter={StaticResource NegationConverter}}"/&gt;
                                  &lt;/DataTemplate&gt;
                              &lt;/sdk:DataGridTemplateColumn.CellEditingTemplate&gt;
                          &lt;/sdk:DataGridTemplateColumn&gt;
  </code></pre>
  
  <p>It seems I can't edit a template of DataGridTextColumn and have to use DataGridTemplateColumn instead as seen above.  This however overrides all the styles I had previously defined within the DataGridStyle. My Column doesn't even have the row marker and looks totally alien to the rest of the cells.</p>
  
  <p>Second problem is, it still doesn't work as intended. The Textbox inside that template is still not set to readonly. What I am doing wrong here?</p>
  
  <p>Highly appreciate your help on this,</p>
  
  <p><strong>Update</strong></p>
  
  <p>After the promising response below I have adjusted the code yet no success.</p>
  
  <p>I have changed the DP's callback to the following</p>
  
  <pre><code>public class IsReadOnlyDpAttachable
      {
          public static void SetIsReadXOnly(DependencyObject obj, bool isReadOnly)
          {
              obj.SetValue(IsReadXOnlyProperty, isReadOnly);
          }
  
          public static bool GetIsReadXOnly(DependencyObject obj)
          {
              return (bool)obj.GetValue(IsReadXOnlyProperty);
          }
  
          public static readonly DependencyProperty IsReadXOnlyProperty =
              DependencyProperty.RegisterAttached("IsReadXOnly", typeof(bool), typeof(IsReadOnlyDpAttachable), new PropertyMetadata(false, Callback));
  
          private static void Callback(DependencyObject d, DependencyPropertyChangedEventArgs e)
          {
              ((DataGrid)d).IsReadOnly = (bool)e.NewValue;
          }
      }
  </code></pre>
  
  <p>And set the DP on the DataGrid's IsReadOnly itself, it works perfectly fine, but then again here I wouldn't need it since the IsReadOnly here is already a Dp and can be easily bound anyway. But the test shows the Dp works fine:</p>
  
  <pre><code>&lt;sdk:DataGrid PrismExt:IsReadOnlyDpAttachable.IsReadXOnly="{Binding IsInEditMode, Mode=TwoWay, Converter={StaticResource NegationConverter}}" Style="{StaticResource DataGridStyle}" CanUserReorderColumns="True" x:Name="call_dataGrid" AutoGenerateColumns="False" ItemsSource="{Binding Calls}"&gt;
  </code></pre>
  
  <p>However the moment I try to utilize the DP on the underlying DataGridTextColumn, it doesn't do anything:</p>
  
  <pre><code>&lt;Grid x:Name="LayoutRoot"&gt;
  &lt;sdk:DataGrid Style="{StaticResource DataGridStyle}" CanUserReorderColumns="True" x:Name="call_dataGrid" AutoGenerateColumns="False" ItemsSource="{Binding Calls}"&gt;
                      &lt;sdk:DataGrid.Columns&gt;                        
                          &lt;sdk:DataGridTextColumn Header="Call Time" Binding="{Binding Path=CallTime}" PrismExt:IsReadOnlyDpAttachable.IsReadXOnly="{Binding DataContext.IsInEditMode, ElementName=LayoutRoot, Mode=TwoWay, Converter={StaticResource NegationConverter}}"/&gt;
                      &lt;/sdk:DataGrid.Columns&gt;
  &lt;/sdk:DataGrid&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p>Any idea?</p>