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

Can I add a theme on a whole page?

6 Answers 165 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
danparker276
Top achievements
Rank 2
danparker276 asked on 17 Apr 2013, 05:55 PM
I can set the theme for the whole app, but can I for a usercontrol?

6 Answers, 1 is accepted

Sort by
0
Maciej
Top achievements
Rank 1
answered on 18 Apr 2013, 12:43 PM
Yes you can  just add

StyleManager.ApplicationTheme = new Office_BlackTheme();

 
in User controls constructor

0
danparker276
Top achievements
Rank 2
answered on 18 Apr 2013, 07:30 PM
That doesn't work.
StyleManager.ApplicationTheme = new Telerik.Windows.Controls.Windows8Theme();
Then it sets the application theme.  Every control I open after that will have that theme.  I only want that one user control to have that theme. 
0
Todor
Telerik team
answered on 19 Apr 2013, 12:44 PM
Hello Dan,

As Maciej wrote, you can set the theme in the UserControl's constructor through our StyleManager. It's strange that there is a problem with that setup as we are unaware of any.

Please, ensure you that you're setting the theme in exactly that UserControl, on which you want to apply the theme, and not in your main application window. If the problem still exists, it will be great if you can send us a project with that issue.

The other approach I can suggest is to set locally a theme to each control which you want to style. For an example, let's say that you want to set the Windows8 theme to a RadComboBox. Here is the way to do this:
<telerik:RadComboBox Width="200" Height="30" telerik:StyleManager.Theme="Windows8">
For your convenience, I've attached a sample demo project which illustrates that approach.

If you have any further questions, please do not hesitate to contact us again.

All the best,
Todor
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
danparker276
Top achievements
Rank 2
answered on 19 Apr 2013, 06:28 PM
I modified the example to show what I'm describing.
here's a link to download it:
http://bboy360.com/bboy/usercontroltheme.zip

Basically when I add another usercontrol, mycontrol2.  It gets set by mycontrol1.
So doing this:
        public MyUserControl()
        {
            StyleManager.ApplicationTheme = new Windows8Theme();
            InitializeComponent();
        }

will set my other user controls.  The main page stayed with no theme though.
0
Accepted
Todor
Telerik team
answered on 22 Apr 2013, 12:56 PM
Hello Dan,

By design, the main purpose of the StyleManager is to be able to set a theme to all our and most of Microsoft controls in your application easily. Therefore, once a Theme is set through StyleManager, it will be used for all user controls created after that.

For your case, I can suggest three approaches. In my opinion, the first one is the most appropriate and reasonable one. Here they are:

1. Use implicit styles and merge the necessary resource dictionaries from the desired theme, in the UserControl on which you want to apply a theme. Please, find the attached project which illustrates this approach.
2. As I wrote in my previous post, you can set a theme to the controls in the UserControl locally.
3. If you still want to use StyleManager, you should set an application theme in the constructor of all UserControls. If you do not do that, the theme which is set to the last UserControl will be applied to the UserControls which are initialized after it. This means that if you declare "UC1" with Windows8Theme, after that you declare "UC2" with VistaTheme and lastly you declare "UC3" without a theme, VistaTheme will be applied to "UC3".

Again, the first way to style your application is the most recommended one.

Hope this helps.


All the best,
Todor
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
danparker276
Top achievements
Rank 2
answered on 23 Apr 2013, 01:33 AM
Yeah, option 1 will work, thanks
Tags
General Discussions
Asked by
danparker276
Top achievements
Rank 2
Answers by
Maciej
Top achievements
Rank 1
danparker276
Top achievements
Rank 2
Todor
Telerik team
Share this question
or