Search code examples
wpfxamlwpfdatagrid

wpf datagridcheckboxcolumn style


Imagine I have a CheckBox custom style named "MyCheckBoxStyle".

How can I make a Datagrid style that embeds a custom DataGridCheckBoxColumn style based on my MyCheckBoxStyle?


Solution

  • You can use DataGridTemplateColumn to create a custom checkboxcolumn

                                    <Custom:DataGridTemplateColumn x:Name="gdchk" Header="Test" MaxWidth="50">
                                    <Custom:DataGridTemplateColumn.CellTemplate >
                                        <DataTemplate>
                                            <CheckBox IsChecked="{Binding Path = classname}" HorizontalAlignment="Center" Style="{DynamicResource myCheckBoxStyle}"/>
                                        </DataTemplate>
                                    </Custom:DataGridTemplateColumn.CellTemplate>
                                </Custom:DataGridTemplateColumn>
    

    Hope this helps.