RadGridView: Changing colour of a sorted HeaderCell

4 posts, 0 answers
  1. Kenneth
    Kenneth avatar
    1 posts
    Member since:
    Oct 2015

    Posted 09 Feb Link to this post

     

    Greetings

    Currently I'm not that experienced with styles in WPF and after some research I decided to give it a shot to ask. 

    I'm working with with the RadGridView and I'd like to change the Foreground of the header of a sorted column. 

    Within the styles of Telerik I found there are some visual states to determine the colour of the border or for the ascending/ descending arrow. Yet there is no description to change the colour of the Foreground. 

    Yet doing some research, I found some code to add to change the Foreground as well within the VisualState. 

    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Content" Storyboard.TargetProperty="(TextBlock.Foreground)">
        <DiscreteObjectKeyFrame KeyTime="0" Value="White" />
    </ObjectAnimationUsingKeyFrames>

    Yet, this isn't working. This entirely breaks the VisualState of 'Ascending'/ 'Descending' and the following exception within Output can be found:

    A first chance exception of type 'System.InvalidOperationException' occurred in PresentationFramework.dll

    Sorry for asking perhaps a dumb question. I'm still in the learning process of Telerik styles and WPF styles in general. 

    Kind regards

    Kenneth

  2. Stefan X1
    Admin
    Stefan X1 avatar
    523 posts

    Posted 12 Feb Link to this post

    Hi Kenneth,

    For achieving this, you need to modify the template of GridViewHeaderCell. I suggest you taking a look at the Implicit Styles topic, as well at the Styling Column Headers one for more information on this matter.

    So, within the ControlTemplate of GridViewHeaderCell you should be able to find the two VisualStates with x:Name="Ascending" and x:Name="Descending". Both of them use the SolidColorBrush with x:Key="GridView_HeaderForeground_Selected". You can modify it as per your requirements.

    I have also attached a sample application as a demonstration.

    Hope it helps.

    Regards,
    Stefan X1
    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
  3. UI for WPF is Visual Studio 2017 Ready
  4. Mark
    Mark avatar
    16 posts
    Member since:
    Sep 2012

    Posted 22 Jun in reply to Stefan X1 Link to this post

    This post was very helpful to me thank you!
  5. Mark
    Mark avatar
    16 posts
    Member since:
    Sep 2012

    Posted 22 Jun in reply to Stefan X1 Link to this post

    This post was very helpful to me thank you!
Back to Top