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

About GridViewHeaderCellStyle

5 Answers 124 Views
GridView
This is a migrated thread and some comments may be shown as answers.
mao ruixian
Top achievements
Rank 1
mao ruixian asked on 14 Jul 2010, 08:37 AM
MyCode is :

 

 

<Style TargetType="gridviewTelerik:GridViewDataColumn">    
    <Setter Property="HeaderCellStyle" Value="{StaticResource GridViewHeaderCellStyle}"/>    
</Style
  
  
<Style x:Key ="GridViewHeaderCellStyle" TargetType="HeaderCellStyle"
    <Setter Property="HorizontalContentAlignment" Value="Center" />    
</Style


Throw the exception:
Cannot find a Resource with the Name/Key GridViewHeaderCellStyle [Line: 731 Position: 50]

Could you do me a favor?

 

 

5 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 14 Jul 2010, 09:01 AM
Hello mao ruixian,

Please use the following XAML :
<Grid x:Name="LayoutRoot" Background="White">
    <Grid.Resources>
        <Style x:Key ="GridViewHeaderCellStyle" TargetType="gridviewTelerik:GridViewHeaderCell">
            <Setter Property="HorizontalContentAlignment" Value="Right" />
        </Style>
        <Style TargetType="gridviewTelerik:GridViewDataColumn">
            <Setter Property="HeaderCellStyle" Value="{StaticResource GridViewHeaderCellStyle}"/>
        </Style>
    </Grid.Resources>
      
      
    <gridviewTelerik:RadGridView >
        <gridviewTelerik:RadGridView.Columns>
            <gridviewTelerik:GridViewDataColumn HeaderCellStyle="{StaticResource GridViewHeaderCellStyle}"  ...

The reason for the exception was the order of styles were declared in XAML .
There were two more problems :

1. TargetType="HeaderCellStyle" is incorrect
2.  You can not set style for the columns because they are not true visuals. That is why in my XAML I set the style explicitly on the column.


Greetings,
Pavel Pavlov
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
mao ruixian
Top achievements
Rank 1
answered on 14 Jul 2010, 09:10 AM
HI Pavel,
Thanks for your answer.

But I just wondering if I could control the style of ColumnHeader by a global file like the style of TextBlock or sth. else?
You mean the Columns are so special that can not be set by Style?
0
Pavel Pavlov
Telerik team
answered on 14 Jul 2010, 09:13 AM
Hello mao ruixian,

Indeed.. columns are special - they are not UIElements and can not be targeted by style.
However for your case there is a simple solution -
You may set a global style directly for the HeaderCell. No need to bother with columns.
All you need is a global style targeting GridViewHeader cell without a key.
Such as :
<Grid.Resources>
           <Style TargetType="gridviewTelerik:GridViewHeaderCell">
               <Setter Property="HorizontalContentAlignment" Value="Right" />
           </Style>
       </Grid.Resources>

This modified XAML should affect all the Header cells .
Hope that helps.

All the best,
Pavel Pavlov
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
mao ruixian
Top achievements
Rank 1
answered on 14 Jul 2010, 09:52 AM
xmlns:gridviewTelerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView"
    xmlns:gridviewTelerikGrid="clr-namespace:Telerik.Windows.Controls.GridView;assembly=Telerik.Windows.Controls.GridView"  
  
  <Style TargetType="gridviewTelerikGrid:GridViewHeaderCell">
            <Setter Property="HorizontalContentAlignment" Value="Center" />
  </Style>
  
 <gridviewTelerik:RadGridView   MaxHeight="268"  MaxWidth="925">                        
                        <gridviewTelerik:RadGridView.Columns>                          
                            <gridviewTelerik:GridViewDataColumn  Header="Order"/>
                        </gridviewTelerik:RadGridView.Columns>
</gridviewTelerik:RadGridView>

Sorry it still doesn't make sense.
Any problems in my codes? Please help me and thank you in advance.
0
Pavel Pavlov
Telerik team
answered on 15 Jul 2010, 03:31 PM
Hi mao ruixian,
To avoid further confusion , I have prepared a sample project with a centered header.

Please use the attached project  as a starting point.

Regards,
Pavel Pavlov
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
mao ruixian
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
mao ruixian
Top achievements
Rank 1
Share this question
or