Access column properties from header style

2 posts, 1 answers
  1. Pablo
    Pablo avatar
    8 posts
    Member since:
    Feb 2016

    Posted 31 May Link to this post

    Hello team,

    I'm trying to acces IsReadOnly property from header style to change its foreground color. For now, I didn't find a solution. I'm trying the following:

    <Style x:Key="GridViewHeaderCellStyle" TargetType="{x:Type telerik:GridViewHeaderCell}">

    ...

    <Style.Triggers>
                <DataTrigger Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type telerik:GridViewDataColumn}}, Path=Column.IsReadOnly}" Value="false">
                    <Setter Property="Foreground" Value="{DynamicResource primaryBrush}" />
                </DataTrigger>
            </Style.Triggers>
        </Style>

  2. Answer
    Martin Vatev
    Admin
    Martin Vatev avatar
    90 posts

    Posted 03 Jun Link to this post

    Hello Pablo,

    To achieve the desired behavior, you should set the RelativeSourceMode to Self. For reference, please take a look at code snippet below:
    <telerik:RadGridView.Resources>
                    <Style TargetType="{x:Type telerik:GridViewHeaderCell}">
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=Self}, Path=Column.IsReadOnly}" Value="True">
                                <Setter Property="Foreground" Value="Red" />
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
    </telerik:RadGridView.Resources>

    I hope that this helps.


    Regards,
    Martin Vatev
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top