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

[Solved] Use global styles within GridRowStyle

4 Answers 168 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Geir-Tore
Top achievements
Rank 1
Geir-Tore asked on 02 Mar 2011, 07:34 AM
Hi,

I'm currently working on styling a RadGridView with a custom RowStyle. What I want is that the controls in my ControlTemplate (textblocks) should use the style which I have set for my textblocks globally for the entire application. It seems though that although I set my own RowStyle, it uses styles from the RadTheme instead of picking up the style which is globally set for textblocks.

Is there any way that I can reset the style within a RadGridRow so that it picks up my global style for textblocks? Preferably without resorting to named styles.

4 Answers, 1 is accepted

Sort by
0
Vanya Pavlova
Telerik team
answered on 02 Mar 2011, 01:56 PM
Hello Geir-Tore,

 
If you define an implicit style targeted at TextBlock element, it will be applied to all TextBlocks in RadGridView and it will override the default Foreground of GridViewRow. May you provide a bit more details about your exact settings ? How do you define the styles for the row and the TextBlock ?

 

Best wishes,
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!
0
Geir-Tore
Top achievements
Rank 1
answered on 02 Mar 2011, 02:20 PM
Hi and thanks for the reply,

The textblock is styled from our Shell xaml, by importing resourcedictionaries based on selected application theme (currently we're switching between the themes provided by the Silverlight team (Cosmopolitan, Jetpack, AccentColor, ..). Any time I use a textblock (outside any RadControl) I get the style set from the theme.

This does not seem to apply when I set a custom RowStyle for the RadGridView (based on the example at http://demos.telerik.com/silverlight/#GridView/CustomRowLayout) where I need to set the Style property on the textblock to a named style to get what I want.

Examples of styles being set in our application:

## App.xaml
<Application.Resources>
  <ResourceDictionary>
    <ResourceDictionary.MergedDictionaries>
      <ResourceDictionary Source="Themes/Cosmopolitan.xaml"/>
    </ResourceDictionary.MergedDictionaries>
  </ResourceDictionary>
</Application.Resources>

## Cosmopolitan.xaml
<ResourceDictionary.MergedDictionaries>
  <ResourceDictionary Source="Cosmopolitan/CoreStyles.xaml"/>
</ResourceDictionary.MergedDictionaries>

## CoreStyles.xaml
<Style TargetType="TextBlock" x:Key="DefaultTextBlockStyle">
  ....forecolor, fontfamily, size, etc
</Style>

<Style TargetType="TextBlock" BasedOn="{StaticResource DefaultTextBlockStyle}" />
0
Geir-Tore
Top achievements
Rank 1
answered on 02 Mar 2011, 02:45 PM
Btw, here is my current ControlTemplate which is used as RowStyle:

<ControlTemplate x:Key="ActivityRowTemplate">
            <Border Margin="3" BorderThickness="1">
                <Grid Margin="3">
                    <Grid.RowDefinitions>
                        <RowDefinition />
                        <RowDefinition />
                        <RowDefinition />
                        <RowDefinition />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>

                    <Rectangle Width="6" VerticalAlignment="Stretch" HorizontalAlignment="Left" Grid.RowSpan="2" Fill="{Binding Color}" Margin="0,0,8,0" />

                    <TextBlock Grid.Column="1" Text="{Binding ActivityType}" />
                    <TextBlock Grid.Column="1" Grid.Row="1" Text="{Binding Heading}" />
                    <TextBlock Grid.Column="1" Grid.Row="2" Text="{Binding Case}" />
                    <TextBlock Grid.Column="1" Grid.Row="3" Text="{Binding Customer}" />
                    <TextBlock Grid.Column="1" Grid.Row="4" Text="{Binding DateTime}" />
                    
                    <StackPanel Orientation="Horizontal" Grid.Column="2">
                        <TextBlock Text="Pri: " />
                        <TextBlock Text="{Binding Priority}" />
                    </StackPanel>

                </Grid>
            </Border>
        </ControlTemplate>

I have a couple of questions regarding custom row styles like this. First, I do not get any selection on my row items. Do I need to provide a selection style in my custom rowstyle? Second, grid lines (horizontal) does not seem to be shown. Is that intentional when customizing the row style?
0
Vanya Pavlova
Telerik team
answered on 02 Mar 2011, 05:19 PM
Hello Geir-Tore,

 
Thank you for the detailed information about your case. When you define a custom template for any RadGridView part, you have to manually build the behavior you need.
Due to the template structure of GridViewRow it is better to set the Foreground property directly on a row level and it will be applied to all TextBlock elements within this custom layout, as shown below:

<Style x:Key="a1" TargetType="telerik:GridViewRow">
        <Setter Property="Foreground" Value="Red"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="telerik:GridViewRow">
                        <Border Background="Gray">
                            <TextBlock Foreground={TemplateBinding Foreground} Text="{Binding Property1}"/>
                            </Border>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

Also you may set the styles for these TextBlock elements explictily, please refer to the following forum thread:
http://forums.silverlight.net/forums/p/206457/484833.aspx

The situation is the same when you need to add some different states to this custom row layout in a similar way as it is implemented by default, you may download sample project that demonstrates how this can be achieved following this link:

http://www.telerik.com/community/forums/silverlight/gridview/highlight-selected-row-in-radgridview-with-custom-row-layout.aspx

 

Greetings,
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
Geir-Tore
Top achievements
Rank 1
Answers by
Vanya Pavlova
Telerik team
Geir-Tore
Top achievements
Rank 1
Share this question
or