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

Dynamically assigning custom theme to standard silverlight controls

4 Answers 110 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Alan Fisher
Top achievements
Rank 1
Alan Fisher asked on 18 Mar 2011, 12:53 PM
Hi,

I have successfully developed a number of custom themes which are being applied to Telerik controls at the application level. I understand that to assign the theme to standard silverlight controls, I have to use the telerik:StyleManager.Theme on individual controls. The theme is being selected at runtime so I need to dynamically allocate the them to the standard controls in XAML. I am thinking it would be something like:
 <TextBlock Text="Hello" Grid.Row="1" telerik:StyleManager.Theme="{StyleManager.ApplicationTheme}" />

Can someone point me in the right direction?

Regards
Alan


4 Answers, 1 is accepted

Sort by
0
Alan Fisher
Top achievements
Rank 1
answered on 19 Mar 2011, 12:14 AM
From further searching, I think I have top set a property on each page and use it, similar to the technique described in http://www.telerik.com/community/forums/silverlight/general-discussions/how-do-you-set-app-wide-theme-for-telerik-controls-amp-ms-controls.aspx

It would be great if I could set each control directly to StyleManager.ApplicationTheme though so if anyone has some thoughts it would be greatly appreciated

Alan
0
Vanya Pavlova
Telerik team
answered on 21 Mar 2011, 01:49 PM
Hi Alan,

 
The Telerik themes are designed to work mainly with our RadControls and some native Silverlight controls. Some of them are TextBox, ListBox, ScrollBar, CheckBox, Button etc. Our theming mechanism cannot cover the full control list included either in Silverlight or in WPF. In our online documenation you may find a very useful information about the theming mechanism that we offer and how it can be applied to different RadControls.
If you need any additional information, please let me know.

All the best,
Vanya Pavlova
the Telerik team
0
Alan Fisher
Top achievements
Rank 1
answered on 21 Mar 2011, 10:29 PM
Hi Vanya,

Thanks for your reply. I had already read all the documentation and have custom themes working (sortof). My question was more about what is the best way to assign a theme to a standard silverlight control where the theme isnt known until runtime. i.e I would like to do something like <TextBlock Text="Hello" Grid.Row="1" telerik:StyleManager.Theme="{StyleManager.ApplicationTheme}" />. Do you have any suggestions?

Also, I can only get my theme working using [ThemeLocation(ThemeLocation.External)] rather than [ThemeLocation(ThemeLocation.BuiltIn)]. How do I decide which attribute to use?

Regards
Alan
0
Vanya Pavlova
Telerik team
answered on 22 Mar 2011, 04:52 PM
Hello Alan,

 
When you change the application theme, the controls do not update their default styles as you need to recreate the whole visual tree. You may switch between the themes at runtime, but you will need to reload the whole view. On the other hand, instead of setting application theme, you could use the telerik:StyleManager.Theme attached property on every Telerik control (and some of the standard Silverlight controls) to specify a theme.
I have prepared an example for you that demonstrates how to dynamically change the theme using RadComboBox.
Regarding your second question: The ThemeLocation is an enumeration which is used to distinguish between built-in and custom themes with members Built-In and External.
The Built-In attrubute represents a theme developed by Telerik and hosted in the control assembly. 
The External attribute represents a theme hosted in an external assembly.
You may see at the following online help article "Creating a Custom Theme Project - Using the Telerik Approach" that is defined a non-existent file Generic.xaml. Thus when the Telerik StyleManager uses a Theme class with ThemeLocation=BuiltIn, it ignores the path to the XAML file and replaces it with ";component/themes/[control assembly].xaml". In this example the Telerik StyleManager will replace the
provided path with "/MyTheme;component/Themes/Telerik.Windows.Controls.xaml".


Greetings,
Vanya Pavlova
the Telerik team
Tags
General Discussions
Asked by
Alan Fisher
Top achievements
Rank 1
Answers by
Alan Fisher
Top achievements
Rank 1
Vanya Pavlova
Telerik team
Share this question
or