Extract theme properties

2 posts, 1 answers
  1. David A.
    David A. avatar
    126 posts
    Member since:
    Aug 2008

    Posted 30 Mar 2011 Link to this post

    Hi.  I have a CommandBarButton that I would like to set the backcolor to whatever the "hover" backcolor is for the current theme.  (This is a visual cue to the user and a toggle button is not appropriate).  I have tried using button.SetValue and button.ResetValue but I can't seem to find out what the backcolor is for the hover state. 

    Is it possible at runtime to extract properties for certain states from a theme?

    Thank you!
  2. Answer
    Ivan Todorov
    Ivan Todorov avatar
    688 posts

    Posted 04 Apr 2011 Link to this post

    Hi David A.,

    Thank you for writing.

    There is no way you can extract the theme properties for a given state, but there is a way to achieve the behavior you are asking for. In order to do this, you should override the OnShown method of your form as follows:
    protected override void OnShown(EventArgs e)
        commandBarButton1.VisualState = "CommandBarButton.MouseOver";
        commandBarButton1.SetValue(CommandBarButton.BackColorProperty, commandBarButton1.BackColor);
        commandBarButton1.SetValue(CommandBarButton.BackColor2Property, commandBarButton1.BackColor2);
        commandBarButton1.SetValue(CommandBarButton.BackColor3Property, commandBarButton1.BackColor3);
        commandBarButton1.SetValue(CommandBarButton.BackColor4Property, commandBarButton1.BackColor4);
        commandBarButton1.SetValue(CommandBarButton.NumberOfColorsProperty, commandBarButton1.NumberOfColors);
        commandBarButton1.SetValue(CommandBarButton.GradientStyleProperty, commandBarButton1.GradientStyle);
        commandBarButton1.SetValue(CommandBarButton.GradientPercentageProperty, commandBarButton1.GradientPercentage);
        commandBarButton1.SetValue(CommandBarButton.GradientPercentage2Property, commandBarButton1.GradientPercentage2);
        commandBarButton1.SetValue(CommandBarButton.BorderBoxStyleProperty, commandBarButton1.BorderBoxStyle);
        commandBarButton1.SetValue(CommandBarButton.BorderColorProperty, commandBarButton1.BorderColor);
        commandBarButton1.SetValue(CommandBarButton.BorderInnerColorProperty, commandBarButton1.BorderInnerColor);
        commandBarButton1.SetValue(CommandBarButton.BorderWidthProperty, commandBarButton1.BorderWidth);

    We first set the VisualState property and refresh the theme in order to load the property settings from the theme. Then, we use SetValue for some of the properties that are set through a theme, because doing so, we are setting them as a local value. This means that they will no longer be affected by theme settings. Depending on the theme you are using, there might be some other properties you would have to set as local, because the above set properties are not the only ones that could be set through a theme.

    I hope you find this information useful. If you have any additional questions, do not hesitate to ask.

    Best wishes,
    Ivan Todorov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. DevCraft banner
Back to Top