Cannot Resolve: GridViewAlternateRowStyle

6 posts, 0 answers
  1. Scott
    Scott avatar
    8 posts
    Member since:
    Apr 2016

    Posted 20 Sep Link to this post

    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.

     

  2. Scott
    Scott avatar
    8 posts
    Member since:
    Apr 2016

    Posted 20 Sep in reply to Scott Link to this post

    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.

  3. UI for WPF is Visual Studio 2017 Ready
  4. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    368 posts

    Posted 21 Sep Link to this post

    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.
  5. Scott
    Scott avatar
    8 posts
    Member since:
    Apr 2016

    Posted 21 Sep in reply to Dilyan Traykov Link to this post

    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...

  6. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    368 posts

    Posted 26 Sep Link to this post

    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.
  7. Scott
    Scott avatar
    8 posts
    Member since:
    Apr 2016

    Posted 26 Sep in reply to Dilyan Traykov Link to this post

    Works like a dream! Thank you Dilyan!
Back to Top
UI for WPF is Visual Studio 2017 Ready