Setting the current cell border to inactive color when GridView looses focus

3 posts, 0 answers
  1. Arthur
    Arthur avatar
    22 posts
    Member since:
    Jul 2014

    Posted 18 Nov 2014 Link to this post


    I have a styling question:

    When a GridView looses focus it is possible to set the background of a GridViewRow to a color that indicates, that the selection is inactive (like Selector.IsSelectionActive). Now at the same time, I want to set the Background_Current border of a GridViewCell to an inactive color. Because there is no VisualState like "CurrentUnfocused" on a GridViewCell, I do not know how to achieve this.

    I thought about binding somehow to the state of the parent row, but could not find a way. Any ideas?

  2. Arthur
    Arthur avatar
    22 posts
    Member since:
    Jul 2014

    Posted 18 Nov 2014 Link to this post

    Finally I found a solution:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using Telerik.Windows.Controls.GridView;
    namespace XXX
        public static class RowSelectionActiveProvider
            public static readonly DependencyProperty IsRowSelectionActiveProperty =
                    new PropertyMetadata(false));
            public static Boolean GetIsRowSelectionActive(GridViewRow target)
                if (target == null)
                    return false;
                return (Boolean)target.GetValue(IsRowSelectionActiveProperty);
            public static void SetIsRowSelectionActive(GridViewRow target, Boolean value)
                if (target != null)
                    target.SetValue(IsRowSelectionActiveProperty, value);

    In the GridViewRow style:

    <VisualState x:Name="Selected">
                        <DiscreteBooleanKeyFrame Value="True" KeyTime="0"/>

    In the GridViewCell style:
        <DataTrigger Binding="{Binding (local:RowSelectionActiveProvider.IsRowSelectionActive), RelativeSource={RelativeSource AncestorType={x:Type telerik:DataCellsPresenter}}}"
            <Setter TargetName="Background_Current"

    Puh, hours wasted, but it works.

  3. Vanya Pavlova
    Vanya Pavlova avatar
    2019 posts

    Posted 19 Nov 2014 Link to this post

    Hi Arthur,

    I'm glad to hear you were able to find an appropriate solution for your case.
    Have a great day. 

    Vanya Pavlova

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

Back to Top