This is a migrated thread and some comments may be shown as answers.

Change Background color of selected row

3 Answers 568 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Marnic
Top achievements
Rank 1
Marnic asked on 03 Jan 2018, 02:47 PM

Hi,

Is there an easy way (= without having to use a complex ControlTemplate like in Kalin Milanovs answer (https://www.telerik.com/forums/how-to-change-the-selected-row-style)) to change the backgound color of the selected row ?

I've tried using a Trigger:

    <Style x:Key="DefaultTelerikGridViewRowStyle" TargetType="telerik:GridViewRow">
        <Setter Property="Height" Value="20"/>
        <Style.Triggers>
            <Trigger Property="IsSelected" Value="True">
                <Setter Property="Height" Value="24"/>
                <Setter Property="BorderBrush" Value="Green" />
                <Setter Property="BorderThickness" Value="3" />
                <Setter Property="FontWeight"  Value="Bold" />
                <Setter Property="FontSize" Value="14"/>
                <Setter Property="Background" Value="Red"/>
                <Setter Property="Foreground" Value="Green"/>
            </Trigger>
        </Style.Triggers>
    </Style>

This works fine for every property in the Trigger, except for the Background color.  How come ?

Kind Regards

 

3 Answers, 1 is accepted

Sort by
0
Vladimir Stoyanov
Telerik team
answered on 05 Jan 2018, 03:46 PM
Hello,

The background is actually set to Red with the style from the provided example, however there is a VisualState in the ControlTemplate of the GridViewRow which overrides this. You can check that the Background is Red by inspecting the application with a Xaml inspection tool like Snoop. So in order to change the background of the selected row it is needed to modify the ControlTemplate of the GridViewRow. You can read some more on that topic in the Editing Control Templates article. I am attaching a project with the ControlTemplate for the GridViewRow extracted for your reference and I have inserted a comment indicating where you can change the row Background when it is selected. 

Regards,
Vladimir Stoyanov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Marnic
Top achievements
Rank 1
answered on 08 Jan 2018, 01:18 PM

Hello Vladimir,

thanks for your reply.  I'm relatively new to WPF and a novice when it comes to styling, control templates, ... so, to me, it seems like a whole lot of overhead having to copy the complete ControlTemplate in my style class just to be able to change the background color of the selected row. Is there realy no easier solution ?

I copied your XAML code for the template and pasted it into my "DefaultTelerikGridViewRowStyle" (as shown in my first post).  Everything compiles fine but when I run the application and open a window with a RadGridView, the application freezes and no data is shown.  Any idea why because I don't have a clue.  Your sample project runs fine.

Best Regards.

0
Vladimir Stoyanov
Telerik team
answered on 10 Jan 2018, 03:31 PM
Hello,

This is the only way to modify the background of the selected row as there is no other way to remove the selected visual state.

As for nothing showing up when you open a window, please make sure you are using the NoXaml dlls in your application. Additionally, you need to base your style on the theme's default one by setting the BasedOn property like in the sample project from my previous reply.

Do let me know how this goes. If you still come across the same issue, please send over the project you're using so that I can investigate and suggest a solution. I look forward to your reply.

Regards,
Vladimir Stoyanov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
GridView
Asked by
Marnic
Top achievements
Rank 1
Answers by
Vladimir Stoyanov
Telerik team
Marnic
Top achievements
Rank 1
Share this question
or