Dynamically assigning custom theme to standard silverlight controls

5 posts, 0 answers
  1. Alan Fisher
    Alan Fisher avatar
    14 posts
    Member since:
    Nov 2009

    Posted 18 Mar 2011 Link to this post

    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


  2. Alan Fisher
    Alan Fisher avatar
    14 posts
    Member since:
    Nov 2009

    Posted 18 Mar 2011 Link to this post

    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
  3. Vanya Pavlova
    Admin
    Vanya Pavlova avatar
    2019 posts

    Posted 21 Mar 2011 Link to this post

    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
  4. Alan Fisher
    Alan Fisher avatar
    14 posts
    Member since:
    Nov 2009

    Posted 21 Mar 2011 Link to this post

    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
  5. Vanya Pavlova
    Admin
    Vanya Pavlova avatar
    2019 posts

    Posted 22 Mar 2011 Link to this post

    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
Back to Top