C1Theme: how to query e.g. C1FlexGrid colors

Posted by: wknauf on 11 August 2019, 11:53 pm EST

  • Posted 11 August 2019, 11:53 pm EST

    Hi C1,

    my use case: I build a C1FlexGrid which does not use default row alternate logic: e.g. we might have several rows for a date value, and all those rows should either have no back color or the default back color.

    This gets complicated when using C1Theme where I have to pick the alternate back color from theme.

    Attached is a sample.

    Apparently, there are two places where the C1FlexGrid alternate backcolor can be defined:
    a) "BaseThemeProperties\AltBackColor"
    b) "C1FlexGrid\Styles\Alternate\Background" - this is in my sample style ("RainerOrange") just a reference to the global "AltBackColor".

    So, I tried to query the current back color this way:
     Color colorBack = themeCurrent.GetColor("C1FlexGrid\\Styles\\Alternate\\Background");

    This will crash with an "InvalidCastException".

    My workaround:
     ThemeItem themeItem = themeCurrent.Children.GetItemByPath("C1FlexGrid\\Styles\\Alternate\\Background");
    ThemePropBase propBase = (ThemePropBase)themeItem;
    ThemeSolidBackground solidBack = (ThemeSolidBackground) propBase.Value;
    Color colorBack = solidBack.Color.Value;

    Is it a bug that "themeCurrent.GetColor("C1FlexGrid\\Styles\\Alternate\\Background");" does not work? Or should I use a different path?

    The base color can be fetched with "themeCurrent.GetColor("BaseThemeProperties\\AltBackColor");". But I don't know whether any of your default themes have a different C1FlexGrid alternate back color, so I don't know whether is is sufficient to query the back color.

    Best regards

  • Replied 12 August 2019, 10:10 pm EST


    This is the right way to fetch the background. When you query the background it is type of ThemeSolidBackground not a color type that's why InvalidCastException occurs.
    You can get the background even by using the following lines of code:
    C1.Win.C1Themes.ThemeSolidBackground  defaultColor = (C1.Win.C1Themes.ThemeSolidBackground)c1Theme1.GetEnum("C1FlexGrid\\Styles\\Alternate\\Background");

  • Replied 13 August 2019, 5:50 pm EST

    Thanks. But why does the method "GetEnum" return a class here ;-)? I would have never tried to use it because of the name and because the description also speaks about enums ;-).

  • Replied 19 August 2019, 2:55 pm EST


    I have escalated the issue to our development team(394455) and will inform you once I get any information from them.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels