Issue with Telerik DataGrid Cell Style

1 Answer 14 Views
Telerik Trainer
John
Top achievements
Rank 1
John asked on 29 May 2024, 05:32 AM
In our WPF project, we have an issue with the Telerik data grid that,
> We have implemented a cell style for setting the background colour based on condition by using the MultiValue Converter,

 

Style code:

<Style x:Key="AFLinkCellFGStyle" TargetType="telerik:GridViewCell" BasedOn="{StaticResource {x:Type telerik:GridViewCell}}">
                <Style.Resources>
                <local:AFCellLinkFGConverter x:Key="AFCellLinkFGConverter"/>
                </Style.Resources>
                <Setter Property="Background"> 
                    <Setter.Value>
                    <MultiBinding Converter="{StaticResource AFCellLinkFGConverter}">
                        <Binding RelativeSource="{RelativeSource Self}"/>
                        <Binding />
                    </MultiBinding>
                    </Setter.Value>
                </Setter>
                <Style.Triggers>
                    <Trigger Property="IsSelected" Value="True">
                        <Setter Property="Foreground" Value="Black"/>
                        <Setter Property="FontWeight" Value="ExtraBold"/>
                    </Trigger>
                </Style.Triggers>
            </Style>

 

Converter code:

 public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            if (values[1] is ArcFlashEvalRecord)
            {
                Efx.Assert(values[1] is ArcFlashEvalRecord && (values[1] as ArcFlashEvalRecord).pData != null, "FIX THIS - expecting ArcFlashEvalRecord and ArcBusData");
                GridViewCell cell = values[0] as GridViewCell;
                ArcFlashEvalRecord record = values[1] as ArcFlashEvalRecord;
                GridViewColumn column = cell.Column;
                if (column != null)
                {
                    AF_FieldType field_type = (AF_FieldType)column.GetValue(AttachedProp.TagProperty);
                    return AFCellInfo.GetCellInfo(field_type, record).BgBrush;
                }
            }
            return null;
        }

 

Issue: The issue is the background colour is not set properly for each cell.


Description: Initially the data is loaded and the Telerik data gets rendered in the display, we have more than 10 columns, and some of the last columns are hidden. Initially, the background colour worked properly for all cells. but when we horizontally scroll to the end of the data grid to see the hidden columns, at that time, the background of the cell is not set properly, it randomly sets the background colour for hidden column cells. it's changing every time we scroll.

1 Answer, 1 is accepted

Sort by
0
Stenly
Telerik team
answered on 31 May 2024, 01:16 PM

Hello John,

Working directly with the visual elements of RadGridView is not suggested due to the UI virtualization feature of the control.

Instead, these elements should be customized via the available API. In this scenario, the CellStyleSelector functionality could be used. Instead of retrieving the GridViewCell and working with it directly, via a custom StyleSelector, you could work directly with the underlying object inside the SelectStyle method and return different Style instances based on certain conditions.

More information about the CellStyleSelector can be found in the below link:

WPF DataGrid - CellStyleSelector - Telerik UI for WPF

With this being said, I hope the provided information will be of help to you.

Regards,
Stenly
Progress Telerik

A brand new ThemeBuilder course was just added to the Virtual Classroom. The training course was designed to help you get started with ThemeBuilder for styling Telerik and Kendo UI components for your applications. You can check it out at https://learn.telerik.com
Tags
Telerik Trainer
Asked by
John
Top achievements
Rank 1
Answers by
Stenly
Telerik team
Share this question
or