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

Custom Style dynamic Inheritance of theme

4 Answers 330 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Anatoliy
Top achievements
Rank 2
Anatoliy asked on 01 Oct 2013, 08:25 AM
Hi, Telerik!

     I need to override default theme "Office_Black" and save ability for dynamically theme changing. I looked around this help (http://www.telerik.com/help/wpf/styling-apperance-themes-runtime.html). And found problem with inheritance styles. It's need using BasedOn attribute to inherite my default theme. This attribute is limited to StaticResources.
     How can I dynamically change custom style base theme? Hope for the further request!

Regards,
Anatoliy

4 Answers, 1 is accepted

Sort by
0
Anatoliy
Top achievements
Rank 2
answered on 03 Oct 2013, 07:25 AM
Hi, Telerik!

     I have created some helper class for setting default theme. In it I applied StyleManager.ApplicationTheme with needed default theme. I can switch it dynamically with traverse the whole controls tree to set the theme of each control.

But still RadComboBox's Theme value is null (is attached). Can you explain why so?

One more detail if Items are binding only SelectedBox is incorrect, if not it have Office_Black theme at all.
0
Rosen Vladimirov
Telerik team
answered on 08 Oct 2013, 07:20 AM
Hello Anatoliy,

May I ask you to share more details on your case? How do you traverse the visual tree, how do you apply the changes, why aren't you able to use ImplictStyles? If you can share your style, we can give you some hints how you can use it to change the themes. Unfortunately we are not able to give you exact fix based on the currently provided information.

I'm looking forward to hearing from you.

Regards,
Rosen Vladimirov
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Anatoliy
Top achievements
Rank 2
answered on 09 Oct 2013, 07:54 PM
Hello Rosen,

I found the solution to struggle with "RadComboBox's Theme value is null". The reason is that Theme was setting after initialization of RadComboBox's.

But I can make some notes for searcher's community...

How do you traverse the visual tree, how do you apply the changes?
So there're two ways by using 
VisualTreeHelper and LogicalTreeHelper to recursively traverse the visual tree and change DependencyObject.SetProperty(StyleManager.ThemeProperty,theme);
 You need to do some tricks if you want to switch theme at runtime for RadDocking with FloatingPanes (that are ToolWindows).
.

Aren't you able to use ImplictStyles?
If it's possible to use Implicit styles with dynamically changing, please replay me.

Regards,
Anatoliy




0
Rosen Vladimirov
Telerik team
answered on 11 Oct 2013, 06:19 AM
Hi Anatoliy,

I've noticed you have already found our article about switching themes at runtime by using Implicit Styles. In order to workaround your problem with BasedOn attribute you can create different ResourceDictionaries in your application for each theme, for example one will be called Windows8ResourceDictionary, another one will be Office_BlackResourceDictionary, etc. In each of them you will place a code similar to this one:
<ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="/Telerik.Windows.Themes.Office_Black;component/Themes/System.Windows.xaml"/>
    <ResourceDictionary Source="/Telerik.Windows.Themes.Office_Black;component/Themes/Telerik.Windows.Controls.xaml"/>
    <ResourceDictionary Source="/Telerik.Windows.Themes.Office_Black;component/Themes/Telerik.Windows.Controls.Input.xaml"/>
 
     <!-- Merge your styles -->
    <ResourceDictionary Source="/your_assembly_name;component/YourResourceDictionaryWithDefaultStyles.xaml"/>
 
     <!-- Now add styles based on your default styles -->
    <Style TargetType="telerik:RadComboBox" BasedOn="{StaticResource MyDefaultComboStyle}"/>
</ResourceDictionary.MergedDictionaries>

When you change the theme you will clear the merged resources and you will add the resource dictionary for the new theme:
Application.Current.Resources.MergedDictionaries.Clear();
Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary() {
        Source = new Uri("/yourAssemblyName;component/Windows8ResourceDictionary", UriKind.RelativeOrAbsolute)});

Hopefully this helps.

Regards,
Rosen Vladimirov
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
General Discussions
Asked by
Anatoliy
Top achievements
Rank 2
Answers by
Anatoliy
Top achievements
Rank 2
Rosen Vladimirov
Telerik team
Share this question
or