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

GridViewHeaderCell foreground color not changed

1 Answer 124 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Justin
Top achievements
Rank 1
Justin asked on 03 Feb 2011, 03:09 AM
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

1 Answer, 1 is accepted

Sort by
0
Vanya Pavlova
Telerik team
answered on 03 Feb 2011, 05:16 PM
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>>
Tags
General Discussions
Asked by
Justin
Top achievements
Rank 1
Answers by
Vanya Pavlova
Telerik team
Share this question
or