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

Can't set the border of gridviewcell

4 Answers 287 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.
Yuxiao
Top achievements
Rank 1
Yuxiao asked on 19 Sep 2012, 07:18 AM
I create a cell style in xaml file like below:
  <Style x:Key="CellStyle" TargetType="telerik:GridViewCell">
     <Setter Property="BorderThickness" Value="2"/>
     <Setter Property="BorderBrush" Value="Red"/>
 </Style>


and use a class inherited from StyleSelector

public class ColumnStyle : StyleSelector
{
     pulic override Style SelectStyle(object item, DependencyObject container)
    {
         Style style = (App.Current.Resource["CellStyle"]) as Style;
         return style;
    }
}

finnaly I set the style to every column in my gridview.
 
But the border  seems doesn't work.

And I try to set other propery such as background, font size and ect.
They all work.

Could you give me some advise how can I set the border of the cell>
Thank you in advanced!

4 Answers, 1 is accepted

Sort by
0
Vanya Pavlova
Telerik team
answered on 19 Sep 2012, 07:40 AM
Hello Yuxiao,

 

The BorderThickness of a GridViewCell is tightly coupled to the vertical gridlines of RadGridView.
If you want to change the BorderThickness of the cell you should predefine its template using Expression Blend and remove the bindings related to the gridlines. 

You may find below the XAML mark-up as part of GridViewCell's template that should be changed:

<Border x:Name="PART_CellBorder" BorderBrush="{TemplateBinding VerticalGridLinesBrush}" BorderThickness="{Binding VerticalGridLinesWidth, ConverterParameter=Right, Converter={StaticResource GridLineWidthToThicknessConverter}, RelativeSource={RelativeSource TemplatedParent}}" Background="{Binding Background, RelativeSource={RelativeSource TemplatedParent}}"/>


Feel free to modify it in the way you need.  

Regards,
Vanya Pavlova
the Telerik team

Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.

0
Yuxiao
Top achievements
Rank 1
answered on 19 Sep 2012, 09:02 AM
Thank you very much for you advice. And could you give me a simple sample of it?
I tried to modify it as
<Style x:key="CellStyle" TargetType="telerik:GridViewCell">
<Setter Property="Template">
   <Setter.Value>
      <Border x:Name="PART_CellBorder" BorderBrush="Yellow" BorderThickness="5"/>
   </Setter.Value>
</Setter>
</Style>

It seems doesn't work too.
0
Accepted
Vanya Pavlova
Telerik team
answered on 19 Sep 2012, 10:08 AM
Hello Yuxiao,

 

You have missed to specify the ControlTemplate and its TargetType in this style:

<Style x:key="CellStyle" TargetType="telerik:GridViewCell">
<Setter Property="Template">
   <Setter.Value>
    <ControlTemplate TargetType="telerik:GridViewCell">
      <Border x:Name="PART_CellBorder" BorderBrush="Yellow" BorderThickness="5"/>
      </ControlTemplate>
   </Setter.Value>
</Setter>
</Style>


In addition to this if you want to maintain the default behavior of the cell and preserve the hover/selection etc. effects I strongly recommend you to modify the default template of GridViewCell. 


Regards,
Vanya Pavlova
the Telerik team

Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.

0
Yuxiao
Top achievements
Rank 1
answered on 20 Sep 2012, 03:01 AM
Thank you for your support very much
Tags
GridView
Asked by
Yuxiao
Top achievements
Rank 1
Answers by
Vanya Pavlova
Telerik team
Yuxiao
Top achievements
Rank 1
Share this question
or