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

GridView Row Background - change color

5 Answers 500 Views
GridView
This is a migrated thread and some comments may be shown as answers.
ITA
Top achievements
Rank 1
ITA asked on 30 Jul 2012, 09:13 AM
hi,

i'm using the newest Verison of RadCrontrols for WPF. The ItemSource of my gridView is a MVVM (ObservableCollection<Paketdata>).

I my codebehind i run through all the Items in GridView:
var itemsSource = UebersichtDataGrd.ItemsSource as IEnumerable;           
 foreach (Paketdata item in itemsSource)
 {
      if (!string.IsNullOrEmpty(item.Modul))
      {
           // SET Backgroundcolor of GridView row
      }        
}

How do i set the Backgroundcolor of the GridViewRow in this case?
Thanks
Best Regards
Rene

5 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 30 Jul 2012, 09:19 AM
Hi,

I would suggest you to use a RowStyleSelector to achieve your goal.

Greetings,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
ITA
Top achievements
Rank 1
answered on 30 Jul 2012, 09:46 AM
Hi,

that's it, but i can't get it run. I created a class "StadiumCapacityStyle":
using System;
using System.Linq;
using System.Windows.Controls;
using System.Windows;
using ITA_Packetverwaltung.Model.Paketdata;
 
namespace ITA_Packetverwaltung.Module.Uebersicht
{
    public class StadiumCapacityStyle : StyleSelector
    {
        public override Style SelectStyle(object item, DependencyObject container)
        {
            if (item is Paketdata)
            {
                Paketdata club = item as Paketdata;
                if (club.Var10 == "50000")
                {
                    return BigStadiumStyle;
                }
                else
                {
                    return SmallStadiumStyle;
                }
            }
            return null;
        }
        public Style BigStadiumStyle { get; set; }
        public Style SmallStadiumStyle { get; set; }
    }
}

I made a reference in my xaml-file:
xmlns:my="clr-namespace:ITA_Packetverwaltung.Module.Uebersicht"

I tried to add the Grid Resource:

<my:StadiumCapacityStyle x:Key="stadiumCapacityStyle">
<my:StadiumCapacityStyle.BigStadiumStyle>
<Style TargetType="telerik:GridViewRow">
<Setter Property="Background" Value="Red"/>
</Style>
</my:StadiumCapacityStyle.BigStadiumStyle>
<my:StadiumCapacityStyle.SmallStadiumStyle>
<Style TargetType="telerik:GridViewRow">
<Setter Property="Background" Value="White" />
</Style>
</my:StadiumCapacityStyle.SmallStadiumStyle>
</my:StadiumCapacityStyle>

VS2010 tells me: "XAML ... Resource is redundant"

GridView:
<Grid .... RowStyleSelector="{StaticResource stadiumCapacityStyle}">
...
</Grid>

VS2010: the Resource 'stadiumCapacityStyle' could not be resolved!

This is the Copy of you Link-example!
Thanks
Best Regards
Rene
0
ITA
Top achievements
Rank 1
answered on 30 Jul 2012, 02:25 PM
Hi,

problem solved. In the documents this is wrong:
<Grid .... RowStyleSelector="{StaticResource stadiumCapacityStyle}">
...
</Grid>

Correct ist:
<Grid .... RowStyleSelector="{DynamicResource stadiumCapacityStyle}">
...
</Grid>
0
Dimitrina
Telerik team
answered on 31 Jul 2012, 05:58 AM
Hello,

 Thank you for the update.

I have tested the case as you have described but I was able to build the project using 'StaticResource'. The test project I created is attached for a reference. 

All the best,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Nagendra
Top achievements
Rank 1
answered on 27 Sep 2012, 12:55 PM
hi,
how to make  the telerik rad grid header as color full.
I have 5 columns each header should be represented by each color how can i achieve it?
Tags
GridView
Asked by
ITA
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
ITA
Top achievements
Rank 1
Nagendra
Top achievements
Rank 1
Share this question
or