How do I change border color in cell style selector

6 posts, 0 answers
  1. Joshua
    Joshua avatar
    29 posts
    Member since:
    Mar 2011

    Posted 03 May 2011 Link to this post

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

    Posted 03 May 2011 Link to this post

    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
  3. UI for WPF is Visual Studio 2017 Ready
  4. Joshua
    Joshua avatar
    29 posts
    Member since:
    Mar 2011

    Posted 03 May 2011 Link to this post

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

    Posted 03 May 2011 Link to this post

    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
  6. Mark
    Mark avatar
    50 posts
    Member since:
    Dec 2010

    Posted 01 Sep 2015 in reply to Vanya Pavlova Link to this post

    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>
     

     

  7. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 03 Sep 2015 Link to this post

    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
Back to Top
UI for WPF is Visual Studio 2017 Ready