Can't set the border of gridviewcell

5 posts, 1 answers
  1. Yuxiao
    Yuxiao avatar
    19 posts
    Member since:
    Jul 2012

    Posted 19 Sep 2012 Link to this post

    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!
  2. Vanya Pavlova
    Admin
    Vanya Pavlova avatar
    2019 posts

    Posted 19 Sep 2012 Link to this post

    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.

  3. Yuxiao
    Yuxiao avatar
    19 posts
    Member since:
    Jul 2012

    Posted 19 Sep 2012 Link to this post

    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.
  4. Answer
    Vanya Pavlova
    Admin
    Vanya Pavlova avatar
    2019 posts

    Posted 19 Sep 2012 Link to this post

    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.

  5. Yuxiao
    Yuxiao avatar
    19 posts
    Member since:
    Jul 2012

    Posted 19 Sep 2012 Link to this post

    Thank you for your support very much
Back to Top