Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 371
Eduardo Brites Avatar asked May 23 '12 14:05

Eduardo Brites


People also ask

How do I customize the datagridcheckboxcolumn?

You can customize the DataGridCheckBoxColumn by setting properties, such as Width, Header, IsThreeState, and IsReadOnly. If you want to display other types of data, DataGrid provides the following column types: Use to display URI data. Use to display enumeration data. Use to display text.

How to display Boolean data as a checkbox in a DataGrid?

IsThreeState="True" Binding=" {Binding OnlineOrderFlag}" /> </DataGrid.Columns> </DataGrid> Use DataGridCheckBoxColumn to display columns of Boolean data as a CheckBox. The following illustration shows an example of DataGridCheckBoxColumn. To populate the column, bind the column to the data by using the Binding property.

What are the different column types available in DataGrid?

If you want to display other types of data, DataGrid provides the following column types: Use to display URI data. Use to display enumeration data. Use to display text. If you want to use other controls in your DataGrid, you can create your own column types by using DataGridTemplateColumn.

How to use other controls in the DataGrid?

If you want to use other controls in your DataGrid, you can create your own column types by using DataGridTemplateColumn. Initializes a new instance of the DataGridCheckBoxColumn class.


1 Answers

You can simply use your defined style with ElementStyle attribute.

Style defined in resources:

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

And my datagrid checkbox column:

<DataGridCheckBoxColumn ElementStyle="{StaticResource MyCheckBoxStyle}" Binding="{Binding someValue}" />
like image 136
yurislav Avatar answered Sep 16 '22 15:09

yurislav