Can I add a theme on a whole page?

7 posts, 1 answers
  1. danparker276
    danparker276 avatar
    389 posts
    Member since:
    Aug 2010

    Posted 17 Apr 2013 Link to this post

    I can set the theme for the whole app, but can I for a usercontrol?
  2. Maciej
    Maciej avatar
    1 posts
    Member since:
    Apr 2013

    Posted 18 Apr 2013 Link to this post

    Yes you can  just add

    StyleManager.ApplicationTheme = new Office_BlackTheme();

     
    in User controls constructor

  3. UI for WPF is Visual Studio 2017 Ready
  4. danparker276
    danparker276 avatar
    389 posts
    Member since:
    Aug 2010

    Posted 18 Apr 2013 Link to this post

    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. 
  5. Todor
    Admin
    Todor avatar
    168 posts

    Posted 19 Apr 2013 Link to this post

    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.

  6. danparker276
    danparker276 avatar
    389 posts
    Member since:
    Aug 2010

    Posted 19 Apr 2013 Link to this post

    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.
  7. Answer
    Todor
    Admin
    Todor avatar
    168 posts

    Posted 22 Apr 2013 Link to this post

    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.

  8. danparker276
    danparker276 avatar
    389 posts
    Member since:
    Aug 2010

    Posted 22 Apr 2013 Link to this post

    Yeah, option 1 will work, thanks
Back to Top
UI for WPF is Visual Studio 2017 Ready