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

RowStyleSelector and AlternateBackground

4 Answers 292 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Alexander
Top achievements
Rank 1
Alexander asked on 14 Mar 2012, 04:26 PM
Hi!

Maybe its better i start a new Thread for this.
I reffer to this old Topic: http://www.telerik.com/community/forums/wpf/gridview/need-to-change-background-color-of-a-row-based-on-a-condition.aspx

i'am using the StyleSelector to change the background of an GridViewRow in runtime. But i also want to implement an AlternateRowBackground, but - as Tony in the other Topic said - when i set the AlternateRowBackground and AlternationCount-Property in my Grid the StyleSelector doesnt work.
I don't want to create two different Styles for normal Rows and AlternateRows.
Is it possible to set both, RowStyleSelector and AlternateRowBackground or is their a way to implement the AlternateRowBackground in my StyleSelctor? Can i differ if the call comes from the AlternateStyleSelctor or from the RowStyleSelector?


Thank you for your help
Alex

4 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 15 Mar 2012, 09:08 AM
Hi,

 Why not simulate rows alternation with the RowStyleSelector only? In this case you will not have to deal with the grid native alternation and you will keep your code in one place. 

Regards,
Vlad
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Alexander
Top achievements
Rank 1
answered on 15 Mar 2012, 09:12 AM
Hello,

i have tried this, but couldn't come to a solution. How can the StyleSelector know if the row is a "normal" or a alternation row?
In the StyleSelector each row is the same, or is their a differents?

Thank you for your help
0
Accepted
Vlad
Telerik team
answered on 15 Mar 2012, 09:38 AM
Hi Alex,

Alternation usually can be achieve with division. So you can create easily rows alternation with RowStyleSelector:

public class MyRowStyleSelector : StyleSelector
{
    public override System.Windows.Style SelectStyle(object item, System.Windows.DependencyObject container)
    {
        var items = ((GridViewRow)container).GridViewDataControl.Items;
 
        var style = new Style(typeof(GridViewRow));
 
        if (items.IndexOf(item) % 2 == 0)
        {
            style.Setters.Add(new Setter(GridViewRow.BackgroundProperty, new SolidColorBrush(Colors.Red)));
        }
 
        return style;
    }
}
Greetings,
Vlad
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Alexander
Top achievements
Rank 1
answered on 15 Mar 2012, 09:57 AM
Hi Vlad,

i worked with the division, but i didn't come to a solution. Luckly your code works:)
Thank you very much for your help!

Greets Alex
Tags
GridView
Asked by
Alexander
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Alexander
Top achievements
Rank 1
Share this question
or