Toolbox not picking up theme

6 posts, 0 answers
  1. Kristoffer
    Kristoffer avatar
    30 posts
    Member since:
    Oct 2012

    Posted 20 Dec 2012 Link to this post

    I'm switching theme in runtime, as described here:
    http://www.telerik.com/help/wpf/styling-apperance-themes-runtime.html

    All controls pick up the theme changes, except my RadPanelBar. The reason seems to be this line in my XAML:

    <telerik:RadPanelBar ItemContainerStyle="{StaticResource PanelBarItemFirstLevelStyle}" ...

    <Style x:Key="PanelBarItemFirstLevelStyle" TargetType="telerik:RadPanelBarItem" BasedOn="{StaticResource RadPanelBarItemStyle}">
       <Setter Property="ItemContainerStyle" Value="{StaticResource PanelBarItemSecondLevelStyle}" />
    </Style>

    <Style x:Key="PanelBarItemSecondLevelStyle" TargetType="telerik:RadPanelBarItem" BasedOn="{StaticResource RadPanelBarItemStyle}"> ...


    From what I can see, these styles are based on the currently loaded telerik styles. So why don't they pick up the theme change?
  2. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 21 Dec 2012 Link to this post

    Hello Kristoffer,

    We had issues when dynamically changing the theme of the RadPanelBar but only through the StyleManager. So, I tested the control now using the approach described in our documentation and I wasn't able to detect any issues. Can you please have a look at the attached solution and let me know if it works for you or if I've missed something? Thank you in advance.

    Regards,
    Tina Stancheva
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. UI for WPF is Visual Studio 2017 Ready
  4. Kristoffer
    Kristoffer avatar
    158 posts
    Member since:
    Dec 2012

    Posted 11 Jan 2013 Link to this post

    Hmm, I'm seeing this error for other types aswell:

    In app.xaml:
    <Style TargetType="{x:Type telerikNavigation:RadTabItem}" BasedOn="{StaticResource RadTabItemStyle}">
        <Setter Property="MinWidth" Value="80" />
    </Style>
    <ResourceDictionary.MergedDictionaries>
      <ResourceDictionary Source="/Telerik.Windows.Themes.Expression_Dark;component/Themes/System.Windows.xaml"/>
      <ResourceDictionary Source="/Telerik.Windows.Themes.Expression_Dark;component/Themes/Telerik.Windows.Controls.xaml"/>
      <ResourceDictionary Source="/Telerik.Windows.Themes.Expression_Dark;component/Themes/Telerik.Windows.Controls.Chart.xaml"/>
      <ResourceDictionary Source="/Telerik.Windows.Themes.Expression_Dark;component/Themes/Telerik.Windows.Controls.Data.xaml"/>
      <ResourceDictionary Source="/Telerik.Windows.Themes.Expression_Dark;component/Themes/Telerik.Windows.Controls.Diagrams.xaml"/>
      <ResourceDictionary Source="/Telerik.Windows.Themes.Expression_Dark;component/Themes/Telerik.Windows.Controls.Diagrams.Extensions.xaml"/>
      <ResourceDictionary Source="/Telerik.Windows.Themes.Expression_Dark;component/Themes/Telerik.Windows.Controls.Docking.xaml"/>
      <ResourceDictionary Source="/Telerik.Windows.Themes.Expression_Dark;component/Themes/Telerik.Windows.Controls.GridView.xaml"/>
      <ResourceDictionary Source="/Telerik.Windows.Themes.Expression_Dark;component/Themes/Telerik.Windows.Controls.Input.xaml"/>
      <ResourceDictionary Source="/Telerik.Windows.Themes.Expression_Dark;component/Themes/Telerik.Windows.Controls.Navigation.xaml"/>
    </ResourceDictionary.MergedDictionaries>

    That means my tab item style picks up the Dark Expression theme. But when I later change the theme (modifying Application.Current.Resources.MergedDictionaries) the style is still Dark Expression. Hence, my tab item does not pick up the new "BasedOn" theme!
  5. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 16 Jan 2013 Link to this post

    Hi Kristoffer,

    This issue is caused by the custom implicit style you create. When working with styles you need to have in mind that once a style has been applied, it is sealed and cannot be changed. If you want to dynamically change a style that has already been applied, you must create a new style to replace the existing one. For more information, see the IsSealed property.

    And in your case, once you've applied the custom style for the RadTabItems, it is applied to all RadTabItems and even if you dynamically change the default styles, the custom style cannot be updated. You need to manually change it as well but as it is sealed, this means that you'll have to create a new custom style based on the new default RadTabItemStyle.

    Regards,
    Tina Stancheva
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  6. Kristoffer
    Kristoffer avatar
    158 posts
    Member since:
    Dec 2012

    Posted 16 Jan 2013 Link to this post

    Thanks. Does this mean that I have to recreate my custom styles (based on the default styles) from code-behind when I switch theme? Or do I have to, somehow, enumerate all instances of my style and recreate each instance?

    I understand the problem now, but I'm not sure how to fix it. Is it overly complicated? I imagine an API like "recreate all styles" :)
  7. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 17 Jan 2013 Link to this post

    Hello Kristoffer,

    The best approach in this case is to define your custom styles in ResourceDictionaries. This will allow you to merge the dictionary each time you reset the MergedDictionaries collection of the application along with the Telerik theme-related ResourceDictionaries.

    I attached a sample solution demonstrating this approach. Let me know if you have more questions.

    All the best,
    Tina Stancheva
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top
UI for WPF is Visual Studio 2017 Ready