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

TargetType for the RadGridView.ItemContainerStyle

1 Answer 592 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Julien
Top achievements
Rank 1
Julien asked on 03 Mar 2011, 09:00 AM
Hi,

I've to set the background of a cell to a special color. I used the GridViewColumn.CellTemplate.
<telerik:GridViewColumn.CellTemplate>
             <DataTemplate>
                 <Grid Margin="0" Background="{Binding Converter={StaticResource MyFirstConverter}, UpdateSourceTrigger=PropertyChanged}">
                     <CheckBox IsChecked="{Binding ShouldDisplayCalendar, UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Center" IsEnabled="False" />
                 </Grid>
             </DataTemplate>
         </telerik:GridViewColumn.CellTemplate>

My color works, but it doesn't use the whole size of the column. It's because the Grid doesn't take the full size of the column. I found that this is even present with ListView. A workaround is to set the to set HorizontalContentAlignment to stretch through the ItemContainerStyle.

I found example of that for ListView:

<ListView.ItemContainerStyle>
        <Style TargetType="ListViewItem">
                <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
        </Style>
</ListView.ItemContainerStyle>

My only problem is to find the "TargetType" I should put for the RadGridView:

<telerik:RadGridView.ItemContainerStyle>
    <Style TargetType="??????">
        <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
    </Style>
</telerik:RadGridView.ItemContainerStyle>


Could you tell me what I need to put here?

Thank you

1 Answer, 1 is accepted

Sort by
0
Accepted
Vanya Pavlova
Telerik team
answered on 04 Mar 2011, 10:41 AM
Hello Julien,

You have to create a simple style with TargetType GridViewCell, apply this style to this column and the issue will be resolved:

Copy Code
Copy Code
<Window.Resources>
        <Style x:Key="style1" TargetType="telerik:GridViewCell">
            <Setter Property="Padding" Value="0"/>
            <Setter Property="VerticalContentAlignment" Value="Stretch"/>
            </Style>
    </Window.Resources>
    <Grid x:Name="LayoutRoot" DataContext="{Binding Source={StaticResource SampleDataSource}}">
        <telerik:RadGridView  AutoGenerateColumns="False" Margin="41,37,74,82" ItemsSource="{Binding Collection}">
            <telerik:RadGridView.Columns>
                <telerik:GridViewColumn CellStyle="{StaticResource style1}" Header="Column1" Width="100">
                <telerik:GridViewColumn.CellTemplate>
             <DataTemplate>
              ........
             </DataTemplate>
         </telerik:GridViewColumn.CellTemplate>
         </telerik:GridViewColumn>
                </telerik:RadGridView.Columns>
            </telerik:RadGridView>
    


 

Regards,
Vanya Pavlova
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
Tags
GridView
Asked by
Julien
Top achievements
Rank 1
Answers by
Vanya Pavlova
Telerik team
Share this question
or