How do you set App wide Theme for Telerik controls & MS controls?

3 posts, 0 answers
  1. Ben Hayat
    Ben Hayat avatar
    902 posts
    Member since:
    May 2008

    Posted 13 Aug 2009 Link to this post

    After a series of testing, I've come up to one question. How can I set a Theme that will apply to all Telerik controls and MS controls equally without going to each MS control and setting telerik:StyleManager.Theme="Office_Black"?

    If I set any theme in App.cs to be global, none of the MS controls get affected. And if I set each control manually like above, then how can I allow the user to select differnt Theme? I was hoping this issue is resoved by Q2!


    [Update] I created a class in the App.cs that wraps the Telerik.Theme. In the start up, I created a static object of that class.
    Now in my MainPage, based on user request, I can set a property based on Theme selection. (default is set to Office_Black)
    Then in other pages, in the constructor I can set each MS control to the selected theme.
    StyleManager.SetTheme(MyButton, App.NewTheme.MyTheme);

    This solves the problem not having hard coded theme names in each page. But I still have to manually Set each MS control in each page. Is there a way to get around this?

  2. Hristo
    Hristo avatar
    832 posts

    Posted 14 Aug 2009 Link to this post

    Hello Ben,

    Unfortunately we will not be able to apply styles to Microsoft controls (without setting StyleManager.Theme). Silverlight should support implicit styles in order to make this scenario to work.
    However you can bind theme property. If you have Theme property in your Page then you can bind to StyleManager.Theme property to the Page theme property and in page constructor set the theme.

    Here is a simple example:
    <UserControl x:Class="SilverlightApplication1.MainPage" 
      <Grid x:Name="LayoutRoot">  
            <Button Content="asdas" VerticalAlignment="Center" 
                    telerik:StyleManager.Theme="{Binding Theme, ElementName=root}" /> 

    and code-behind:
    using System.Windows;  
    using System.Windows.Controls;  
    using Telerik.Windows.Controls;  
    namespace SilverlightApplication1  
        public partial class MainPage : UserControl  
            public MainPage()  
                this.Theme = new Office_BlackTheme();  
            public Theme Theme  
                get { return (Theme)GetValue(ThemeProperty); }  
                set { SetValue(ThemeProperty, value); }  
            public static readonly DependencyProperty ThemeProperty =  
                DependencyProperty.Register("Theme"typeof(Theme), typeof(MainPage), null);  

    You can further modify the example and pass the Theme in Page constructor.
    I hope this will help you. Let me know if you need more information.

    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. Ben Hayat
    Ben Hayat avatar
    902 posts
    Member since:
    May 2008

    Posted 14 Aug 2009 Link to this post

    Thanks for the sample Hristo for the sample. I'll either take your route or mine. But I guess the end result is that we need to individually set MS controls. Thanks!
Back to Top