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

Cannot Resolve: GridViewAlternateRowStyle

5 Answers 100 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Scott
Top achievements
Rank 1
Scott asked on 20 Sep 2016, 07:10 PM

I have a RadGridView and I've used the article located at: http://docs.telerik.com/devtools/wpf/controls/radgridview/style-selectors/rowstyleselector for styling the row Foreground color. Everything works great except the Alternate Rows have the same color as the "regular" (non-alternate) rows.

I use the "BasedOn" attribute of the style to use the loaded theme (expression_dark) and I thought I would create a second style just for the alternate rows. 

Here is the style code:

<Grid.Resources>
    <my:WorkListStyle x:Key="WorkListStyle">
        <my:WorkListStyle.ViewItem>
            <Style TargetType="telerik:GridViewRow" BasedOn="{StaticResource GridViewRowStyle}">
                <Setter Property="Foreground" Value="Yellow" />
            </Style>
        </my:WorkListStyle.ViewItem>
    </my:WorkListStyle>
    <my:WorkListAltStyle x:Key="WorkListAltStyle">
        <my:WorkListAltStyle.ViewItem>
            <Style TargetType="telerik:GridViewRow" BasedOn="{StaticResource GridViewAlternateRowStyle}">
                <Setter Property="Foreground" Value="Yellow" />
            </Style>
        </my:WorkListAltStyle.ViewItem>
    </my:WorkListAltStyle>
</Grid.Resources>

Then, in the RadGridView, I set these two options:

RowStyleSelector="{StaticResource WorkListStyle}"
AlternateRowStyleSelector="{StaticResource WorkListAltStyle}"

However, I get a run-time error when the xaml is parse on the "GridViewAlternateRowStyle" in the BasedOn attribute. Is there a different StaticResource I should be using? Thank you.

 

5 Answers, 1 is accepted

Sort by
0
Scott
Top achievements
Rank 1
answered on 20 Sep 2016, 07:12 PM

In the post above where I say: "except the Alternate Rows have the same color as the "regular" (non-alternate) rows."

What I meant to say was: "except the Alternate Rows have the same BACKGROUND color as the "regular" (non-alternate) rows. Sorry.

0
Dilyan Traykov
Telerik team
answered on 21 Sep 2016, 09:21 AM
Hello Scott,

As the AlternateRowStyleSelector targets elements of type GridViewRow, you should base the style on the GridViewRowStyle.

As long as you've set RadGridView's AlternationCount property to a value bigger than 1 and have set different background colors in the two respective styles, the appearance of the alternate and non-alternate rows should be different.

For your convenience, I'm attaching a sample project as a reference.

Please let me know if this solves your issue.

Regards,
Dilyan Traykov
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Scott
Top achievements
Rank 1
answered on 21 Sep 2016, 01:03 PM

The project you attached in no way references my problem. As I stated, the *issue* is I simply want to change the FOREGROUND color, NOT the BACKGROUND color of the rows in the grid view based on a simple yes/no question. While the FOREGROUND color does in fact change for both rows and altrows, the altrows have a BACKGROUND color the same as the rows. This is (I'm sure) based on the fact that both rows and altrows use the BasedOn="{StaticResource GridViewCellStyle}" attribute of the <Style> tag.

In the project, you are HARD CODING the background color. I DON'T WANT THIS. What I need is to be able to use the background color of the applied theme. I ONLY want to change the FOREGROUND color of the rows. The ONLY thing I am changing is the foreground color and if I HARD CODE the background color, the user will not be able to change themes because the background color of the grid view will be HARD CODED and that is the opposite of using themes.

What I need is the altrows to have the altrow BACKGROUND color, NOT the row BACKGROUND color. I did in fact have only one style using the BasedOn="{StaticResource GridViewCellStyle}" that works EXCEPT that the BACKGROUND color of the altrows have the same BACKGROUND color of the (regular) rows.

I don't know how else to put it...

0
Dilyan Traykov
Telerik team
answered on 26 Sep 2016, 11:34 AM
Hello Scott,

I do apologize for the misunderstanding. I've modified the project to suit your requirements. Please let me know whether such an approach would work for you.

Regards,
Dilyan Traykov
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Scott
Top achievements
Rank 1
answered on 26 Sep 2016, 01:08 PM
Works like a dream! Thank you Dilyan!
Tags
GridView
Asked by
Scott
Top achievements
Rank 1
Answers by
Scott
Top achievements
Rank 1
Dilyan Traykov
Telerik team
Share this question
or