Set theme global in Q3

12 posts, 0 answers
  1. Kennet
    Kennet avatar
    104 posts
    Member since:
    Jun 2009

    Posted 25 Nov 2009 Link to this post

    ok, my app have some usercontrols that contains Radgrid, Radtreewiew, Radmenu and other Telerik controls.

    How do I easy set Theme for all controls, by code (so I can alow the user to chenge) or by XAML ?
  2. Kennet
    Kennet avatar
    104 posts
    Member since:
    Jun 2009

    Posted 25 Nov 2009 Link to this post

    ok so I found this that works
    public partial class Window1 : Window  
    {  
       public Window1()  
       {  
           StyleManager.ApplicationTheme = new VistaTheme();  
           InitializeComponent();  
       }  

    but how do I change in runtime when app is running, just runing this don't work.
    StyleManager.ApplicationTheme = new Windows7Theme(); 
  3. UI for WPF is Visual Studio 2017 Ready
  4. Valeri Hristov
    Admin
    Valeri Hristov avatar
    2252 posts

    Posted 30 Nov 2009 Link to this post

    Hi Kennet,

    The application themes work only for newly instantiated controls, hence we recommend setting ApplicationTheme before the call to InitializeComponent(). You could workaround this limitation by recreating the page content when changing the theme (we do the same in our online examples).

    Regards,
    Valeri Hristov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  5. Kennet
    Kennet avatar
    104 posts
    Member since:
    Jun 2009

    Posted 30 Nov 2009 Link to this post

    Hi Valeri,

    Thanks, but I can't find in your example code how you change Theme in runtime. Please post C# code.
  6. Valeri Hristov
    Admin
    Valeri Hristov avatar
    2252 posts

    Posted 04 Dec 2009 Link to this post

    Hi Kennet,

    Please, find attached a simple application that changes application themes at runtime.

    Greetings,
    Valeri Hristov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  7. Kennet
    Kennet avatar
    104 posts
    Member since:
    Jun 2009

    Posted 04 Dec 2009 Link to this post

    Thanks Valeri,

    But I need code for WPF, not Silverlight. I tried but can't use the example in WPF.
  8. Valeri Hristov
    Admin
    Valeri Hristov avatar
    2252 posts

    Posted 04 Dec 2009 Link to this post

    Hi Kennet,

    I apologize for that, I overlooked the forum name. I will send you another sample in 20minutes.

    Regards,
    Valeri Hristov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  9. Valeri Hristov
    Admin
    Valeri Hristov avatar
    2252 posts

    Posted 04 Dec 2009 Link to this post

    Hi Kennet,

    Here is the promised application.

    Best wishes,
    Valeri Hristov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  10. Kennet
    Kennet avatar
    104 posts
    Member since:
    Jun 2009

    Posted 04 Dec 2009 Link to this post

    Thanks, but for now I can't use that method since my app only have one window (sure I could but all in a usercontrol, but don't wanna do that). Is there another way to do this?

  11. Valeri Hristov
    Admin
    Valeri Hristov avatar
    2252 posts

    Posted 07 Dec 2009 Link to this post

    Hi Kennet,

    Unfortunately this is the only way to set an application theme with Telerik StyleManager and change it at runtime. You could try binding the StyleManager.Theme attached property on every Telerik control to a property that contains the currently selected theme. However, this would require more work, especially if you have lots of controls.

    All the best,
    Valeri Hristov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  12. Garry Clark
    Garry Clark avatar
    55 posts
    Member since:
    Jan 2005

    Posted 16 Jun 2010 Link to this post

    Kennet,
    I know this is a very old post, but I thought I would respond anyways. Basically the way I am doing this is by basically doing what Valeri said in her last post and I bind to the StyleManager in the Xaml everytime I define a Telerik control as such.

    <telerik:RadButton Name="btn" Width="110" telerik:StyleManager.Theme="{Binding Source={StaticResource settings}, Path=Default.CurrentTheme}"/> 
    and then I have an User Setting called CurrentTheme, which gets updated when a user chooses a new theme from a dropdown list.
    <telerikInput:RadComboBox x:Name="comboTheme" DataContext="{x:Static settings:Settings.Default}" 
                            SelectedItem="{Binding CurrentTheme, Mode=TwoWay}" ItemsSource="{Binding Themes}"   
                                                      telerik:StyleManager.Theme="{Binding Source={StaticResource settings}, Path=Default.CurrentTheme}"/> 
    The ItemSource is tied to another User Setting, but you could tie it to anything. I keep meaning to rework it to pull from something like this:
    ReadOnlyCollection<string> themes = ThemeManager.StandardThemeNames;  
                     
    but have been to lazy to do so.  

    Here is the other related code just in case.
    User Settings
      <userSettings> 
        <EliteExtender.Infrastructure.Properties.Settings> 
          <setting name="Themes" serializeAs="Xml">  
            <value> 
              <ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
                xmlns:xsd="http://www.w3.org/2001/XMLSchema">  
                <string>Office_Blue</string> 
                <string>Office_Black</string> 
                <string>Office_Silver</string> 
                <string>Summer</string> 
                <string>Vista</string> 
                <string>Windows7</string> 
              </ArrayOfString> 
            </value> 
          </setting> 
          <setting name="CurrentTheme" serializeAs="String">  
            <value>Windows7</value> 
          </setting> 
        </EliteExtender.Infrastructure.Properties.Settings> 
      </userSettings> 
     
    Resource Dictionary
    <ResourceDictionary  
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        xmlns:settings="clr-namespace:EliteExtender.Infrastructure.Properties">  
        <ResourceDictionary.MergedDictionaries> 
            <ResourceDictionary> 
                <settings:Settings x:Key="settings" /> 
            </ResourceDictionary> 
        </ResourceDictionary.MergedDictionaries> 
    </ResourceDictionary> 

    Anyhow hope this helps you or someone in someway!
  13. Waleed Seada
    Waleed Seada avatar
    241 posts
    Member since:
    May 2006

    Posted 17 Jan 2011 Link to this post

    Hello there,

    Can anyone tell me how to implement this in a MVVM approach using Q2 2010.

    Best regards
    Waleed
Back to Top
UI for WPF is Visual Studio 2017 Ready