How to set Style for all cells?

3 posts, 0 answers
  1. Martin
    Martin avatar
    7 posts
    Member since:
    Sep 2012

    Posted 08 Apr 2013 Link to this post

    How do you set the style for all cells in an autogenerated GridView in a designer friendly manner?

    ItemContainerStyle has no effect.

    it is possible to handle Columns.CollectionChanged and set Column.CellStyle there, but that approach requires code behind and is invisible at design time.

  2. Vanya Pavlova
    Admin
    Vanya Pavlova avatar
    2019 posts

    Posted 08 Apr 2013 Link to this post

    Hello Martin,

     

    As a rule of thumb if you want to apply a style to all cells in RadGridView you may define an implicit style targeted at GridViewCell, which will be applied to all cells in your grid. An implicit style is the one, which do not require to specify an x:Key attribute. Setting a cell style through the CellStyle property of the column requires a key and should be set manually to the columns you need. Since you need to have design time support the best option here is to define an implicit style in XAML, as shown below:

    <Window
        x:Class="WpfApplication65.MainWindow"
        x:Name="Window"
        Title="MainWindow"
        Width="640" Height="480">
    <Window.Resources>
        <Style TargetType="telerik:GridViewCell">
            <Setter Property="Background" Value="Red"/>
        </Style>
        </Window.Resources>
        <Grid x:Name="LayoutRoot" DataContext="{Binding Source={StaticResource SampleDataSource}}">
            <telerik:RadGridView  ItemsSource="{Binding Collection}"/>
        </Grid>
    </Window>


    Will you clarify how this works for you? 


    All the best,
    Vanya Pavlova
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. Martin
    Martin avatar
    7 posts
    Member since:
    Sep 2012

    Posted 08 Apr 2013 Link to this post

    That works, thanks.
Back to Top