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

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

2 Answers 96 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Arthur
Top achievements
Rank 1
Arthur asked on 18 Nov 2014, 12:59 PM
Hi,

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?

Thx

2 Answers, 1 is accepted

Sort by
0
Arthur
Top achievements
Rank 1
answered on 18 Nov 2014, 03:35 PM
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 =
            DependencyProperty.RegisterAttached(
                "IsRowSelectionActive",
                typeof(bool),
                typeof(RowSelectionActiveProvider),
                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">
    <Storyboard>
        <BooleanAnimationUsingKeyFrames
                     Storyboard.TargetProperty="(local:RowSelectionActiveProvider.IsRowSelectionActive)"
                     Storyboard.TargetName="PART_DataCellsPresenter">
                    <DiscreteBooleanKeyFrame Value="True" KeyTime="0"/>
                 </BooleanAnimationUsingKeyFrames>
        </Storyboard>
</VisualState>

In the GridViewCell style:
<ControlTemplate.Triggers>
    <DataTrigger Binding="{Binding (local:RowSelectionActiveProvider.IsRowSelectionActive), RelativeSource={RelativeSource AncestorType={x:Type telerik:DataCellsPresenter}}}"
             Value="False">
        <Setter TargetName="Background_Current"
                        Property="BorderBrush"
                         Value="Gray"/>
        </DataTrigger>
</ControlTemplate.Triggers>

Puh, hours wasted, but it works.

Thanks
0
Vanya Pavlova
Telerik team
answered on 19 Nov 2014, 09:25 AM
Hi Arthur,


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


Regards,
Vanya Pavlova
Telerik
 

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.

 
Tags
GridView
Asked by
Arthur
Top achievements
Rank 1
Answers by
Arthur
Top achievements
Rank 1
Vanya Pavlova
Telerik team
Share this question
or