GridView Row Background - change color

6 posts, 0 answers
  1. ITA
    ITA avatar
    383 posts
    Member since:
    Aug 2009

    Posted 30 Jul 2012 Link to this post

    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
  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 30 Jul 2012 Link to this post

    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.

  3. UI for WPF is Visual Studio 2017 Ready
  4. ITA
    ITA avatar
    383 posts
    Member since:
    Aug 2009

    Posted 30 Jul 2012 Link to this post

    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
  5. ITA
    ITA avatar
    383 posts
    Member since:
    Aug 2009

    Posted 30 Jul 2012 Link to this post

    Hi,

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

    Correct ist:
    <Grid .... RowStyleSelector="{DynamicResource stadiumCapacityStyle}">
    ...
    </Grid>
  6. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 31 Jul 2012 Link to this post

    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.

  7. Nagendra
    Nagendra avatar
    3 posts
    Member since:
    Mar 2012

    Posted 27 Sep 2012 Link to this post

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