Datagrid text cell edit styling

3 Answers 79 Views
DataGrid
Andres
Top achievements
Rank 1
Iron
Andres asked on 30 Jul 2024, 10:15 PM

How can I style how the text cell appears when editing the value?

It currently looks like this:

 

I want it to be transparent with black text

Andres
Top achievements
Rank 1
Iron
commented on 30 Jul 2024, 10:40 PM

Tried with the following code but it won't respond to Background changes, only TextColor
<telerik:DataGridTextColumn HeaderText="Location" 
                                PropertyName="Location">
    <telerik:DataGridTextColumn.CellEditorStyle>
        <Style TargetType="telerik:RadEntry">
            <Setter Property="ReserveSpaceForErrorView" Value="False" />
            <Setter Property="Margin" Value="2" />
            <Setter Property="Background" Value="White"/>
            <Setter Property="BackgroundColor" Value="White"/>
            <Setter Property="TextColor" Value="Red"/>

        </Style>
    </telerik:DataGridTextColumn.CellEditorStyle>
</telerik:DataGridTextColumn>

3 Answers, 1 is accepted

Sort by
1
Accepted
Yana
Telerik team
answered on 02 Aug 2024, 10:16 AM

Hello Andres,

I am sorry for my confusion regarding this ticket.  Indeed, the RadEntry background color cannot be changed directly, as it is applied through visual states. Please try it like this:

<telerik:DataGridTextColumn.CellEditorStyle>
    <Style TargetType="telerik:RadEntry">
        <Setter Property="ReserveSpaceForErrorView" Value="False" />
        <Setter Property="Margin" Value="2" />
        <Setter Property="VisualStateManager.VisualStateGroups">
            <VisualStateGroupList>
                <VisualStateGroup x:Name="CommonStates">
                    <VisualState x:Name="Normal">
                        <VisualState.Setters>
                            <Setter Property="BackgroundColor" Value="{AppThemeBinding Light=Black, Dark=White}" />
                            <Setter Property="TextColor" Value="{AppThemeBinding Light=White, Dark=Black}" />
                        </VisualState.Setters>
                    </VisualState>

                    <VisualState x:Name="Focused">
                        <VisualState.Setters>
                            <Setter Property="BackgroundColor" Value="{AppThemeBinding Light=Green, Dark=Blue}" />
                            <Setter Property="TextColor" Value="{AppThemeBinding Light=White, Dark=Black}" />
                        </VisualState.Setters>
                    </VisualState>

                    <VisualState x:Name="Disabled">
                        <VisualState.Setters>
                            <Setter Property="BackgroundColor" Value="Pink" />
                        </VisualState.Setters>
                    </VisualState>

                    <VisualState x:Name="PointerOver">
                        <VisualState.Setters>
                            <Setter Property="BackgroundColor" Value="{AppThemeBinding Light=Gray, Dark=Red}" />
                            <Setter Property="TextColor" Value="{AppThemeBinding Light=White, Dark=Black}" />
                        </VisualState.Setters>
                    </VisualState>
                </VisualStateGroup>
            </VisualStateGroupList>
        </Setter>
    </Style>
</telerik:DataGridTextColumn.CellEditorStyle>

and let me know how it goes.

Regards,
Yana
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.

Andres
Top achievements
Rank 1
Iron
commented on 02 Aug 2024, 08:31 PM

Yana, 

This works great! One last thing. Is there anywhere else I can place this so I don't need to add the code in every TextColumn and have it applied for all datagrids throught my app?

Yana
Telerik team
commented on 05 Aug 2024, 08:48 AM

I am afraid that wouldn't be possible. Anyway, you can define the CellEditorStyle as a resource and reference it as a StaticResource for each TextColumn. 

I hope this would be an acceptable solution.

Andres
Top achievements
Rank 1
Iron
commented on 05 Aug 2024, 11:50 AM

Can you please show me how to do that?
Yana
Telerik team
commented on 05 Aug 2024, 01:14 PM

Just add the Style with a x:Key to the page or App.xaml resources:

 

<Style x:Key="MyCellEditorStyle"
        TargetType="telerik:RadEntry">
    <Setter Property="ReserveSpaceForErrorView" Value="False" />
    <Setter Property="Margin" Value="2" />
    <Setter Property="VisualStateManager.VisualStateGroups">
        <VisualStateGroupList>
            <VisualStateGroup x:Name="CommonStates">
                <VisualState x:Name="Normal">
                    <VisualState.Setters>
                        <Setter Property="BackgroundColor" Value="{AppThemeBinding Light=Black, Dark=White}" />
                        <Setter Property="TextColor" Value="{AppThemeBinding Light=White, Dark=Black}" />
                    </VisualState.Setters>
                </VisualState>

                <VisualState x:Name="Focused">
                    <VisualState.Setters>
                        <Setter Property="BackgroundColor" Value="{AppThemeBinding Light=Green, Dark=Blue}" />
                        <Setter Property="TextColor" Value="{AppThemeBinding Light=White, Dark=Black}" />
                    </VisualState.Setters>
                </VisualState>

                <VisualState x:Name="Disabled">
                    <VisualState.Setters>
                        <Setter Property="BackgroundColor" Value="Pink" />
                    </VisualState.Setters>
                </VisualState>

                <VisualState x:Name="PointerOver">
                    <VisualState.Setters>
                        <Setter Property="BackgroundColor" Value="{AppThemeBinding Light=Gray, Dark=Red}" />
                        <Setter Property="TextColor" Value="{AppThemeBinding Light=White, Dark=Black}" />
                    </VisualState.Setters>
                </VisualState>
            </VisualStateGroup>
        </VisualStateGroupList>
    </Setter>
</Style>

And set it to the TextColumn's CellEditorStyle:

<telerik:DataGridTextColumn PropertyName="Country"
                        CellEditorStyle="{StaticResource MyCellEditorStyle}"/>

 

Andres
Top achievements
Rank 1
Iron
commented on 05 Aug 2024, 01:15 PM

Thanks a lot
0
Yana
Telerik team
answered on 31 Jul 2024, 09:19 AM

Hi Andres,

CellEditorStyle sets the style to the concrete editor, in the case of TextColumn - to the RadEntry.  You would need to use CellDecorationStyle property to apply a background to the cell:

<telerik:DataGridTextColumn.CellDecorationStyle>
    <telerik:DataGridBorderStyle BackgroundColor="#E0F2F1" />
</telerik:DataGridTextColumn.CellDecorationStyle>

Please try it like this and let me know how it goes.

Regards,
Yana
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.

Andres
Top achievements
Rank 1
Iron
commented on 31 Jul 2024, 05:17 PM

Yana,

What I want to edit is the concrete editor, meaning the RadEntry, as pointed in your response. However, the Editor is not responding to the changes I made.

This is how it looks with the change you proposed. I need the editor that's in dark grey to look white.

Andres
Top achievements
Rank 1
Iron
commented on 31 Jul 2024, 05:18 PM

BTW - This is only happening on Windows. My system is in dark mode as well.
0
Andres
Top achievements
Rank 1
Iron
answered on 31 Jul 2024, 05:16 PM

Yana,

What I want to edit is the concrete editor, meaning the RadEntry, as pointed in your response. However, the Editor is not responding to the changes I made.

This is how it looks with the change you proposed. I need the editor that's in dark grey to look white.

Tags
DataGrid
Asked by
Andres
Top achievements
Rank 1
Iron
Answers by
Yana
Telerik team
Andres
Top achievements
Rank 1
Iron
Share this question
or