Implicit style support for bound columns

Feb 20, 2009 at 12:46 PM
Do DataGridBoundColumns such as DataGridCheckBoxColumn support implicit styling? I try to make all the check boxes in my app look same (including the check boxes in DataGridCheckBox columns). Normal implicit styling like below doesn't seem to work (this is defined in ResourceDictionary):

<Style TargetType="{x:Type CheckBox}">
...
</Style>

Neither does this approach (this is also defined in ResourceDictionary):

<Style TargetType="{x:Type Toolkit:DataGridCheckBoxColumn}">
  <Setter Property="ElementStyle">
    <Setter.Value>
      <Style TargetType="{x:Type CheckBox}">
      ...
      </Style>
    </Setter.Value>
  </Setter>
</Style>

However, if I define style explicitly it seems to work, but this is something I wouldn't like to do (this is defined in directly inside DataGrid definition):

<Toolkit:DataGridCheckBoxColumn Header="..."
                                                          Binding="...">
  <Toolkit:DataGridCheckBoxColumn.ElementStyle>
    <Style TargetType="{x:Type CheckBox}">
    ...
    </Style>
  </Toolkit:DataGridCheckBoxColumn.ElementStyle>
</Controls:DataGridCheckBoxColumn>

So, is there a mechanism for implicitly defining style for DataGridBoundColumns (maybe something like the style keys with Toolbar) or do I have to define all styles explicitly?
Feb 23, 2009 at 5:46 AM
Does anybody know answer to this?
Coordinator
Feb 23, 2009 at 5:32 PM
Hi annyman,

DataGridColumn derives from DependencyObject, and therefore does not have a Style property.  For an explanation of why this is, see this thread: http://www.codeplex.com/wpf/Thread/View.aspx?ThreadId=37611.

Instead, you'll want to apply a Style to the visual element in the cell.  In the case above, you'd want to apply it to CheckBox.  Alternatively, you can use the explicit ElementStyle like you did above also.

Thanks,
Samantha