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

How do I change border color in cell style selector

5 Answers 890 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Joshua
Top achievements
Rank 1
Joshua asked on 03 May 2011, 08:08 AM
I'm using a cell style selector and want to be able to set the border color of a cell. Setting the background color works fine. My code looks something like this:


<my:CellStyleSelector.SmallStadiumStyle>
                    <Style TargetType="telerik:GridViewCell">
                        <Setter Property="Background" Value="Yellow" />
                        <Setter Property="BorderBrush" Value="White"/>
                    </Style>
                </my:CellStyleSelector.SmallStadiumStyle>

5 Answers, 1 is accepted

Sort by
0
Vanya Pavlova
Telerik team
answered on 03 May 2011, 08:17 AM
Hello Joshua,

 
Considering the template structure of GridViewCell, using a simple style you may reset the BorderThickness in this way:

<my:CellStyleSelector.SmallStadiumStyle>
                    <Style TargetType="telerik:GridViewCell">
                        <Setter Property="BorderThickness" Value="0"/>
                        <Setter Property="Background" Value="Yellow" />
                    </Style>
</my:CellStyleSelector.SmallStadiumStyle>


With this snippet you will reset only the outer border of GridViewCell. If this does not satisfy your needs, you have to edit its template and add it to your StyleSelector. 


Kind regards,
Vanya Pavlova
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Joshua
Top achievements
Rank 1
answered on 03 May 2011, 08:33 AM
The border thickness or borderbrush properties don't seem to do anything. The background color does work though. I have uploaded my source code (without the dlls) here:
http://www.megaupload.com/?d=WEEOP3W5

I am using .net 4 and the telerik dlls are version 2011.1.315.40.
0
Vanya Pavlova
Telerik team
answered on 03 May 2011, 10:08 AM
Hello Joshua,

 
Thank you for sharing these files with us!
If you take a look at the default template of GridViewCell you may see that the default BorderThickness is set to 0,0,1,0. This border is related to the RadGridView's gridlines and if you want to change this behavior you have to edit the template of GridViewCell in order to maintain its original settings (states, colors etc.). I will try to demonstrate you with a simple style, which you may use in your StyleSelector:

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


Using this style you will loose the default GridViewCell's states and its behavior in the corresponding state. 
 

Kind regards,
Vanya Pavlova
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Mark
Top achievements
Rank 1
answered on 01 Sep 2015, 08:31 AM

Vanya, I need to set the background as well as the border. simply adding the background setter does not work (border sets perfectly).

<Style  x:Key="IsEventStyle"
                TargetType="telerik:GridViewCell">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="telerik:GridViewCell">                
                <Border BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}">
                    <ContentPresenter Content="{TemplateBinding Content}"
                                                        ContentTemplate="{TemplateBinding ContentTemplate}" />
                </Border>                  
            </ControlTemplate>
        </Setter.Value>
    </Setter>
    <Setter Property="BorderThickness"
                    Value="0.5,1,0.5,1"></Setter>
    <Setter Property="Margin"
                    Value="0,1,0,1" />
    <Setter Property="BorderBrush"
                    Value="Navy"></Setter>
    <Setter Property="VerticalAlignment"
                    Value="Stretch" />
    <Setter Property="HorizontalAlignment"
                    Value="Stretch" />
    <Setter Property="Background"
                    Value="PapayaWhip" />
</Style>
 

 

0
Dimitrina
Telerik team
answered on 03 Sep 2015, 01:55 PM
Hello,

You should specify the Background to the redefined Border directly:
<Border BorderBrush="{TemplateBinding BorderBrush}"
    BorderThickness="{TemplateBinding BorderThickness}" Background="PapayaWhip">

Regards,
Dimitrina
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
GridView
Asked by
Joshua
Top achievements
Rank 1
Answers by
Vanya Pavlova
Telerik team
Joshua
Top achievements
Rank 1
Mark
Top achievements
Rank 1
Dimitrina
Telerik team
Share this question
or