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

Extract theme properties

1 Answer 41 Views
CommandBar
This is a migrated thread and some comments may be shown as answers.
David A.
Top achievements
Rank 1
David A. asked on 30 Mar 2011, 07:55 PM
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!

1 Answer, 1 is accepted

Sort by
0
Accepted
Ivan Todorov
Telerik team
answered on 04 Apr 2011, 03:39 PM
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)
{
    base.OnShown(e);
    commandBarButton1.VisualState = "CommandBarButton.MouseOver";
    commandBarButton1.ForceReApplyStyle(true);
 
    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
Tags
CommandBar
Asked by
David A.
Top achievements
Rank 1
Answers by
Ivan Todorov
Telerik team
Share this question
or