Change selected row background color

4 posts, 0 answers
  1. Leo
    Leo avatar
    2 posts
    Member since:
    Apr 2009

    Posted 10 Apr 2013 Link to this post

    I created the following style:

    <Style TargetType="telerik:GridViewRow" BasedOn="{StaticResource {x:Type telerik:GridViewRow}}">
                 
                <Setter Property="Background" Value="LightGray" />
     
                <Style.Triggers>
                    <Trigger Property="IsSelected" Value="True">
                        <Setter Property="Background" Value="CornflowerBlue" />
                        <Setter Property="Foreground" Value="White"/>
                    </Trigger>
     
                    <Trigger Property="IsMouseOver" Value="True">
                        <Setter Property="Background" Value="LightBlue" />
                    </Trigger>
                </Style.Triggers>
            </Style>

    Everything works perfectly except this line:
    <Setter Property="Background" Value="CornflowerBlue" />

    So, how can I set the background color of a selected row?
  2. Yoan
    Admin
    Yoan avatar
    1066 posts

    Posted 11 Apr 2013 Link to this post

    Hello Leo,

    If you want to modify the appearance of the selected row, you can predefine its template using Microsoft Expression Blend. There you should modify the Border element named Background_Selected in the way you need. I can suggest you to check this help article for a reference.

    I hope this information helps.

    Greetings,
    Yoan
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. UI for WPF is Visual Studio 2017 Ready
  4. Alexander
    Alexander avatar
    3 posts
    Member since:
    Nov 2015

    Posted 18 Nov 2015 in reply to Yoan Link to this post

    Hello.

    In my scenario, I don't want to change the default style or a default color of the selected row. But in certain conditions, I would like to change the selection color of the specific row.

    For example from the SelectionChanged event handler of RadGridView, if a certain condition occurs, I would like to highlight the selected row (or rows) in a different color.

    The problem is that there is no such property like:

    myGrid.SelectedItem.Background = Brushes.Red  (and I want this to happen only for this specific time, and not always)

     

    I hope you can help me,

    Thanks in advance

  5. Yoan
    Admin
    Yoan avatar
    1066 posts

    Posted 23 Nov 2015 Link to this post

    Hello Alexander,

    You can achieve your goal, by using a RowStyleSelector. Please check this help article for a reference. In your case, you can add a property of the business object (for example "IsActive") which will control when the row will switch its color. Then in the selection changed event, after some custom logic, you can set the IsActive property to True and the row should change its color.

    Regards,
    Yoan
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top