DataGridColumnHeaderStyle won't let me use DynamicResource bindings

1 Answer 39 Views
DataGrid
Angus
Top achievements
Rank 1
Iron
Iron
Angus asked on 29 Feb 2024, 02:37 PM

Hi there,

I am trying to style my dataGrid and I can't seem to use dynamic bindings for background colors etc. Whenever I do I get type mismatch compilation errors. 

If I switch to StaticResources it works just fine.

For app themes I obviously need these values to be dynamic. 

Any idea what I'm doing wrong here? Background styles and binding works correctly throughout the app so the binding is correct. It just doesn't want to compile for this control.

Thanks!

Angus

1 Answer, 1 is accepted

Sort by
0
Didi
Telerik team
answered on 29 Feb 2024, 03:04 PM

Hello Angus,

DynamicResources in DataGridCellStyle and BorderStyle

From the code, you have sent I see that you want to set the color through the dynamic resource. That's not gonna work because the DataGridCellStyle class does not support property binding. This is described in the error message you get in visual studio Error List window.

We have this behavior logged as a feature request in our feedback portal: DataGrid: Provide support for property binding in DataGridBorderStyle and DataGridCellStyle class.

You can subscribe to the items to track their progress in order to receive an email notification when there is an update.

Solution

In order to achieve the result, I suggest you use the AppThemeBinging approach. I could suggest 2 separate DataGridBorderStyles (one for the light theme and one for the dark). I'm providing you with code snippets examples of the 2 DataGridTextCellStyles:

<ContentPage.Resources>
        <telerik:DataGridTextCellStyle x:Key="lightDataGridStyle" 
                                    TextColor="Blue"
                                    FontSize="15" />

        <telerik:DataGridTextCellStyle x:Key="darkDataGridStyle" 
                                     TextColor="Red"
                                     FontSize="15" />
    </ContentPage.Resources>
    <telerik:RadDataGrid x:Name="dataGrid" ItemsSource="{Binding People}" AutoGenerateColumns="False">
        <telerik:RadDataGrid.Columns>
            <telerik:DataGridTextColumn PropertyName="Name" 
                                    CellContentStyle="{AppThemeBinding Light={StaticResource lightDataGridStyle},
                                                                                                Dark={StaticResource darkDataGridStyle}}"/>
            <telerik:DataGridNumericalColumn PropertyName="Age"/>
        </telerik:RadDataGrid.Columns>
    </telerik:RadDataGrid>

Same approach has to be used for header styling, etc.

Regards,
Didi
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Angus
Top achievements
Rank 1
Iron
Iron
commented on 01 Mar 2024, 06:45 AM

Perfect, thanks Didi.

I have added my vote to that feature request :)
Tags
DataGrid
Asked by
Angus
Top achievements
Rank 1
Iron
Iron
Answers by
Didi
Telerik team
Share this question
or