Change Background color of selected row

4 posts, 0 answers
  1. Marnic
    Marnic avatar
    4 posts
    Member since:
    Dec 2017

    Posted 03 Jan Link to this post

    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

     

  2. Vladimir Stoyanov
    Admin
    Vladimir Stoyanov avatar
    178 posts

    Posted 05 Jan Link to this post

    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.
  3. Marnic
    Marnic avatar
    4 posts
    Member since:
    Dec 2017

    Posted 08 Jan Link to this post

    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.

  4. Vladimir Stoyanov
    Admin
    Vladimir Stoyanov avatar
    178 posts

    Posted 10 Jan Link to this post

    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.
Back to Top