GridViewHeaderCell foreground color not changed

2 posts, 0 answers
  1. Justin
    Justin avatar
    3 posts
    Member since:
    Feb 2011

    Posted 02 Feb 2011 Link to this post

    Hi,

    I understand that I can change the GridViewHeaderCell foreground color by setting this,
    <Style TargetType="telerik:GridViewHeaderCell">
        <Setter Property="Background" Value="DarkBlue"/>
        <Setter Property="Foreground" Value="White"/>
        <Setter Property="FontWeight" Value="Bold"/>
        <Setter Property="FontSize" Value="14"/>
    </Style>

    However, if I have already had a default TextBlock style like this,
    <Style TargetType="TextBlock">
        <Setter Property="Foreground" Value="Green"/>   
    </Style>

    This style's foreground color, in this case, the 'Green' will overwrite the GridViewHeaderCell's foreground color White.

    I am not sure if this is a bug or I have missed something.

    Please advise and thanks in advance!
    Justin
  2. Vanya Pavlova
    Admin
    Vanya Pavlova avatar
    2019 posts

    Posted 03 Feb 2011 Link to this post

    Hi Justin,


    This is normal behavior due to the fact you have defined an implicit style targeted at GridViewHeaderCell and second one targeted at TextBlock. The Header property of each column in RadGridView is of type object and you can put everything you need there. The implicit style targeted at TextBlock overrides the one defined in GridViewHeaderCell's style and you may avoid it by predefining the Header property of the corresponding column as it is shown below:

    <UserControl
        x:Class="SilverlightApplication198.MainPage"
        Width="640" Height="480">
    <UserControl.Resources>
    <Style TargetType="telerik:GridViewHeaderCell">
        <Setter Property="Background" Value="DarkBlue"/>
        <Setter Property="Foreground" Value="White"/>
        <Setter Property="FontWeight" Value="Bold"/>
        <Setter Property="FontSize" Value="14"/>
    </Style>
        <Style TargetType="TextBlock">
              <Setter Property="Foreground" Value="Green"/>
        </Style>
        </UserControl.Resources>
        <Grid x:Name="LayoutRoot" Background="White" DataContext="{Binding Source={StaticResource SampleDataSource}}">
            <telerik:RadGridView Margin="116,38,202,0" RowIndicatorVisibility="Collapsed" VerticalAlignment="Top" ItemsSource="{Binding Collection}" Height="288">
                <telerik:RadGridView.Columns>
                    <telerik:GridViewDataColumn  DataMemberBinding="{Binding Property1}">
                         <telerik:GridViewDataColumn.Header>
                            <TextBlock Text="Predefined header" Style="{x:Null}"/>
                        </telerik:GridViewDataColumn.Header>
                        </telerik:GridViewDataColumn>
                    </telerik:RadGridView.Columns>
                </telerik:RadGridView>
            </Grid>
    </UserControl>


    If you need to read more about implicit styles in Silverlight, please follow this link.


    All the best,
    Vanya Pavlova
    the Telerik team
    Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
Back to Top