We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

How to specify custom style for checkbox which is in sfDataGrid cell

I use the sfDataGrid to show data. There's a checkbox control in per row. It works well.

Now, I want to change checkbox's background, I specify my custom style for it, but it didn't work.

You can see my xaml code:

<Page.Resources>
        <Style x:Key="CheckBoxStyle1" TargetType="CheckBox">
            <Setter Property="Background" Value="Red"/>
        </Style>
        <DataTemplate x:Key="cellTemplate">
            <CheckBox Content="abc" IsChecked="{Binding IsChecked}" Style="{StaticResource CheckBoxStyle1}"></CheckBox>
        </DataTemplate>
    </Page.Resources>
    <Page.DataContext>
        <local:ViewModel />
    </Page.DataContext>

    <Grid>

        <syncfusion:SfDataGrid x:Name="dataGrid"
                       AllowFiltering="True"
                       ItemsSource="{Binding Orders}">
            <syncfusion:SfDataGrid.Columns>
                <syncfusion:GridTextColumn HeaderText="Order ID" MappingName="OrderID" />

                <syncfusion:GridTextColumn HeaderText="Customer ID" MappingName="CustomerID" />

                <syncfusion:GridTemplateColumn MappingName="IsChecked" CellTemplate="{StaticResource cellTemplate}">
                </syncfusion:GridTemplateColumn>
                <syncfusion:GridTextColumn HeaderText="Customer Name"

MappingName="CustomerName" />
            </syncfusion:SfDataGrid.Columns>
        </syncfusion:SfDataGrid>
    </Grid>

5 Replies

MK Muthukumar Kalyanasundaram Syncfusion Team March 8, 2017 05:43 PM UTC

Hi Xavier, 

Thank you for contacting Syncfusion support. 

We have checked your code.  You have set the custom style for checkbox control, the style are applied to CheckBox control in GridTemplateColumn. For your reference, we have attached the sample in below location. 


If you want to apply style for  checkbox rectangle, you need to override the checkbox control style and change background for that rectangle instead set background for entire checkbox control. 

Please let us know if you have any query. 

Regards, 
Muthukumar K 



TI Timo March 10, 2017 02:16 AM UTC

Thank you Muthukumar K !

I found a strage scenario. If I install your syncfusion library via ".exe" and add reference to it directly. Then I use your code will not work.

But if I add Package source in visual studio and use NuGet package manager to install your package in my project, then your code will work.

That's why?


MK Muthukumar Kalyanasundaram Syncfusion Team March 10, 2017 06:20 PM UTC

Hi Xavier, 
 
We have checked your query. We are not able to reproduce the reported issue, it’s working fine in our end. Could you please provide your current Syncfusion product version, it will helpful for us to analyze further. 
 
Regards, 
Muthukumar K 



TI Timo replied to Muthukumar Kalyanasundaram March 13, 2017 01:33 AM UTC

Hi Xavier, 
 
We have checked your query. We are not able to reproduce the reported issue, it’s working fine in our end. Could you please provide your current Syncfusion product version, it will helpful for us to analyze further. 
 
Regards, 
Muthukumar K 


Thanks for your help.

The library version is: 14.4.0.15



Attachment: AppDataGrid_636c5dc6.zip


MK Muthukumar Kalyanasundaram Syncfusion Team March 15, 2017 03:49 AM UTC

Hi Xavier, 

We have analyzed the provided sample. It seems CheckBox style not working as expected only when setting TargetVersion as Windows 10 Anniversary Edition.  

 
The same working when setting any other target version as in the below code snippet,
 

It is not an issue with Syncfusion control. This issue was reproduced when using CheckBox alone in application also.  

Please let us know if you have any query. 

Regards, 
Muthukumar K 


Loader.
Up arrow icon