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

Styling GridViewDataColumns and GridViewSelectedColumns in RadGridViews

1 Answer 102 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Beau
Top achievements
Rank 2
Beau asked on 04 Feb 2014, 07:44 PM
Greetings Telerik,

  I have multiple RadGridViews which consist of both GridViewDataColumns as well as GridViewSelectColumns. Is there a way I can set the style for each column type once and have it apply to all RadGridViews? 

If I include this style in the resources section of my application's MainWindow, it works fine and all cells will receive the styling I desire:

<Style TargetType="{x:Type telerik:GridViewCell}">
<Setter Property="VerticalContentAlignment" Value="Top"/>
</Style>


However that will affect checkboxes in GridViewSelectColumns which I would like to remain "centered" regarding their VerticalContentAlignment... so I tried this (also in the resources section of my Mainwindow):

<Style TargetType="{x:Type telerik:GridViewDataColumn}">
    <Setter Property="CellStyle">
        <Setter.Value>
<Style TargetType="{x:Type telerik:GridViewCell}">
<Setter Property="VerticalContentAlignment" Value="Top"/>
</Style>
        </Setter.Value>
</Setter>
</Style>


However it does not seem to apply the styling to any cells... But, if I go to each column in each grid and set the style manually (using the same style) for each one it does work:

<Style x:Key="myStyle"  TargetType="{x:Type telerik:GridViewCell}">
    <Setter Property="VerticalContentAlignment" Value="Top"/>
</Style>

<telerik:RadGridView
            x:Name="mygridview"
            ShowGroupPanel="False"
            ItemsSource="{Binding Path=MyView}"
            AutoGenerateColumns="False"
            SelectionMode="Extended"
            SelectedItem="{Binding Path=SelectedRecord}"
            RowIndicatorVisibility="Collapsed"
            CanUserFreezeColumns="False"
            CanUserDeleteRows="False"
            ScrollMode="Deferred">
    <telerik:RadGridView.Columns>
        <telerik:GridViewSelectColumn />
        <telerik:GridViewDataColumn DataMemberBinding="{Binding Path=RecordName}" CellStyle="{StaticResource myStyle}" />
        <telerik:GridViewDataColumn DataMemberBinding="{Binding Path=RecordName}" CellStyle="{StaticResource myStyle}" />
        <telerik:GridViewDataColumn DataMemberBinding="{Binding Path=RecordName}" CellStyle="{StaticResource myStyle}" />
    </telerik:RadGridView.Columns>
</telerik:RadGridView>


Any advice you could provide would be greatly appreciated. I'm using .NET 4.5.1 with Telerik UI for WPF Q3 2013 SP2 (13.3.1316.0) in Visual Studio 2013. Thanks!

Cheers,
Beau

1 Answer, 1 is accepted

Sort by
0
Accepted
Yoan
Telerik team
answered on 08 Feb 2014, 12:04 AM
Hi Beau,

Generally, if you have only one GridVIewSelectColumn, you can apply an explicit style to it:
<Style TargetType="telerik:GridViewCell" x:Key="mySelectColumnStyle">
            <Setter Property="VerticalContentAlignment" Value="Center"/>
</Style>
    .
    .
<telerik:GridViewSelectColumn CellStyle="{StaticResource mySelectColumnStyle}"/>

then you can apply an implicit style( without x:Key attribute ) for the rest columns:
<Style TargetType="telerik:GridViewCell">
           <Setter Property="VerticalContentAlignment" Value="Top"/>           
</Style>


Regards,
Yoan
Telerik

Check out the new Telerik Platform - the only modular platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native apps. Register for the free online keynote and webinar to learn more about the Platform on Wednesday, February 12, 2014 at 11:00 a.m. ET (8:00 a.m. PT).

Tags
GridView
Asked by
Beau
Top achievements
Rank 2
Answers by
Yoan
Telerik team
Share this question
or