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

Styling issues - Column Background and IsFilterable

1 Answer 38 Views
GridView
This is a migrated thread and some comments may be shown as answers.
David A.
Top achievements
Rank 1
David A. asked on 22 Feb 2012, 08:42 PM

Hi,

I have two styling issues wtih the GridView.  The first is I am trying to by default set a column style to not display the Filter for a column by default (we only have a few columns in each grid that are filterable).  My code is as follows:

<Style  TargetType="telerik:GridViewColumn" >
        <Setter Property="IsFilterable" Value="False"/>
    </Style>

Second, I have a cell style set as well but I now when I set the Background brush for a column it has no affect.  What am I doing wrong?

<Style TargetType="telerik:GridViewCell" >
       <Setter Property="Template">
           <Setter.Value>
               <ControlTemplate TargetType="{x:Type telerik:GridViewCell}">
                   <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
                       <ContentPresenter Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}"/>
                   </Border>
               </ControlTemplate>
           </Setter.Value>
       </Setter>
       <Setter Property="BorderBrush" Value="#FFEFEFEF" />
       <Setter Property="BorderThickness" Value="0,0,1,0" />
       <Setter Property="Margin" Value="2,0,0,0"/>
       <Setter Property="VerticalAlignment" Value="Center"/>
       <Setter Property="HorizontalAlignment" Value="Stretch"/>
        
   </Style>

In the gridview I am setting the background as such:

Any help would be greatly appreciated!
David A.

<telerik:GridViewDataColumn DataMemberBinding="{Binding HoursCompleted}" Header="Hours" UniqueName="HoursCompleted" DataFormatString=" {0:n2}" HeaderTextAlignment="Center" Width="60"  Background="#33FDA500"/>






1 Answer, 1 is accepted

Sort by
0
Accepted
Vanya Pavlova
Telerik team
answered on 27 Feb 2012, 03:12 PM
Hello David,



Since the columns of RadGridView are not visual elements you cannot create a style targeted at GridViewColumn and set any property in similar manner. If you want to apply the specified column Background and your newly created cell style you should set the appropriate Background as shown below:
 
<Style TargetType="telerik:GridViewCell" >
       <Setter Property="Template">
           <Setter.Value>
               <ControlTemplate TargetType="{x:Type telerik:GridViewCell}">
                   <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
                       <ContentPresenter Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}"/>
                   </Border>
               </ControlTemplate>
           </Setter.Value>
       </Setter>
       <Setter Property="BorderBrush" Value="#FFEFEFEF" />
       <Setter Property="BorderThickness" Value="0,0,1,0" />
       <Setter Property="Margin" Value="2,0,0,0"/>
       <Setter Property="VerticalAlignment" Value="Center"/>
       <Setter Property="HorizontalAlignment" Value="Stretch"/>
   </Style>


When you predefine the template of a cell in such manner you will loose any of its effects such as selection, mouseover etc. By that reason I would recommend you to modify the default template of GridViewCell and remove the unused elements. 




Greetings,
Vanya Pavlova
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Tags
GridView
Asked by
David A.
Top achievements
Rank 1
Answers by
Vanya Pavlova
Telerik team
Share this question
or