Find control in ControlTemplate or set alternating background color

3 posts, 0 answers
  1. Mitch Newlin
    Mitch Newlin avatar
    5 posts
    Member since:
    Sep 2009

    Posted 16 Dec 2010 Link to this post

    I'm trying to find a control in my datacolumn's control template at run-time, so I can set the background color.  What I had hoped to do is just set the gridviews alternating row background color, so I wouldn't have to do this, but it's not working.  If you could either tell me how to reference the border control name "ItemBorder" at run-time so I can set it manually, or tell me how to set the gridviews alternating row background color correctly, I would appreciate it. 

    Here is the xaml for my RadGrid:

    <telerik:RadGridView x:Name="gvApplications" RowIndicatorVisibility="Collapsed" ScrollViewer.HorizontalScrollBarVisibility="Hidden" AlternateRowBackground="#DDDDDD" AutoGenerateColumns="false" SelectionMode="Single" EditTriggers="None" ItemsSource="{Binding Applications}" RowDetailsVisibilityMode="Collapsed" ShowColumnHeaders="False" ShowGroupPanel="False" Width="575" HorizontalAlignment="Left"  >
                                <Style TargetType="telerik:GridViewCell">
                                    <Setter Property="Template">
                                            <ControlTemplate TargetType="telerik:GridViewCell">
                                                <Border x:Name="ItemBorder" BorderBrush="#FFC2C2C2" BorderThickness="2, 1, 2, 1" Width="575" HorizontalAlignment="Left" Background="#DDDDDD" Padding="5" Height="101">
                                                    <StackPanel HorizontalAlignment="left" Margin="0" Background="Transparent" Width="565">
                                                        <Grid Width="565" HorizontalAlignment="Left" Height="65" Background="Transparent">
                                                                <RowDefinition Height="0.385*"></RowDefinition>
                                                                <RowDefinition Height="5"></RowDefinition>
                                                                <RowDefinition Height="0.615*"></RowDefinition>
                                                                <ColumnDefinition Width="0.25*"></ColumnDefinition>
                                                                <ColumnDefinition Width="0.282*"></ColumnDefinition>
                                                                <ColumnDefinition Width="0.282*"></ColumnDefinition>
                                                                <ColumnDefinition Width="0.186*"></ColumnDefinition>
                                                            <TextBlock x:Name="tbStudentName" Text="{Binding Path=Student.FullName}" Grid.Column="0" Grid.Row="0"></TextBlock>
                                                            <TextBlock x:Name="tbAddress" Text="{Binding Path=Student.Address}" Grid.Column="0" Grid.Row="2" VerticalAlignment="Top" Height="34"/>
                                                            <TextBlock Text="Card #:" Grid.Column="1" Grid.Row="0" Margin="0,0,18,0"></TextBlock>
                                                            <TextBlock x:Name="tbCardNumber" Text="{Binding Path=Student.GiftCard.CardNumber}" Grid.Column="1" Grid.Row="0" Margin="44,0,8,0"></TextBlock>
                                                            <TextBlock Text="Amount:" Grid.Column="2" Grid.Row="0" Margin="8,0,-8,0"></TextBlock>
                                                            <TextBox x:Name="tbAmount" Text="{Binding Path=Funding.Amount}" Grid.Column="2" Grid.Row="0" RenderTransformOrigin="1.217,0.56" Margin="61,0,8,0"/>
                                                            <TextBox x:Name="tbComments" Grid.Row="2"  Grid.Column="1" Grid.ColumnSpan="2" Margin="68,0,8,3"></TextBox>
                                                            <Button Content="Fund" Click="btnFund_Clicked"  Grid.Column="3" Grid.Row="0" Margin="44,0,8,0" RenderTransformOrigin="0.95,0.48" CommandParameter="{Binding ApplicationID}" Command="{Binding FundCard}"></Button>
                                                            <TextBlock Text="Comments:" Grid.Row="2" Grid.Column="1" Margin="0,0,20,0" Height="15" VerticalAlignment="Top" d:LayoutOverrides="VerticalAlignment"/>
                                                        <Border BorderThickness="2" BorderBrush="#BFDF55" Height="24" Margin="0,0,5,0" Background="#F8FCDF">
                                                            <StackPanel Orientation="Horizontal">
                                                                <Image Source="../Images/Check.png" Height="16" Width="16" Margin="5,0,0,0"></Image>
                                                                <TextBlock x:Name="tbActionText" Text=""></TextBlock>
  2. Vanya Pavlova
    Vanya Pavlova avatar
    2019 posts

    Posted 17 Dec 2010 Link to this post

    Hello Mitch,

    Why do you actually need to access the template of RadGridView? You need to specify the RadGridView's AlternatonCount property which represents the count of alternating items as well as an appropriate color for their background:

    this.radGridView1.AlternateRowBackground=new SolidColorBrush(Colors.Red);

    If you need any further assistance please let me know.

    Kind regards,
    Vanya Pavlova
    the Telerik team
    Browse the videos here>> to help you get started with RadControls for Silverlight
  3. Mitch Newlin
    Mitch Newlin avatar
    5 posts
    Member since:
    Sep 2009

    Posted 17 Dec 2010 Link to this post

    As I said, I didn't want to have to access the cell template, but the alternate row color was not working.  I didn't realize you had to explicitly set the alternation count value, that really seems like something that should have a default value and only be overridden through that property.  In any case, setting that fixes my problem of setting the alternating row background color.  However, for future reference, should I need to access a control in my template, how would I do that?
Back to Top