Kristoffer
Top achievements
Rank 1
Kristoffer
asked on 20 Dec 2012, 01:58 PM
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?
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?
5 Answers, 1 is accepted
0
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
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.
0
Kristoffer
Top achievements
Rank 1
answered on 11 Jan 2013, 04:34 PM
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!
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!
0
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
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.
0
Kristoffer
Top achievements
Rank 1
answered on 16 Jan 2013, 03:01 PM
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" :)
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" :)
0
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
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.