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

Set theme global in Q3

11 Answers 396 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Kennet
Top achievements
Rank 2
Kennet asked on 25 Nov 2009, 06:56 PM
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 ?

11 Answers, 1 is accepted

Sort by
0
Kennet
Top achievements
Rank 2
answered on 25 Nov 2009, 09:46 PM
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(); 
0
Valeri Hristov
Telerik team
answered on 30 Nov 2009, 05:04 PM
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.
0
Kennet
Top achievements
Rank 2
answered on 30 Nov 2009, 07:03 PM
Hi Valeri,

Thanks, but I can't find in your example code how you change Theme in runtime. Please post C# code.
0
Valeri Hristov
Telerik team
answered on 04 Dec 2009, 12:33 PM
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.
0
Kennet
Top achievements
Rank 2
answered on 04 Dec 2009, 01:13 PM
Thanks Valeri,

But I need code for WPF, not Silverlight. I tried but can't use the example in WPF.
0
Valeri Hristov
Telerik team
answered on 04 Dec 2009, 01:22 PM
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.
0
Valeri Hristov
Telerik team
answered on 04 Dec 2009, 01:34 PM
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.
0
Kennet
Top achievements
Rank 2
answered on 04 Dec 2009, 01:58 PM
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?

0
Valeri Hristov
Telerik team
answered on 07 Dec 2009, 01:57 PM
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.
0
Garry Clark
Top achievements
Rank 1
answered on 16 Jun 2010, 06:43 PM
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!
0
Waleed Seada
Top achievements
Rank 2
answered on 17 Jan 2011, 04:11 PM
Hello there,

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

Best regards
Waleed
Tags
General Discussions
Asked by
Kennet
Top achievements
Rank 2
Answers by
Kennet
Top achievements
Rank 2
Valeri Hristov
Telerik team
Garry Clark
Top achievements
Rank 1
Waleed Seada
Top achievements
Rank 2
Share this question
or