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

Dynamic Implicit theme issue with BasedOn Style

3 Answers 399 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Niko
Top achievements
Rank 1
Niko asked on 21 Feb 2014, 12:25 AM
Hello,

I have implemented implicit themes using the Merged Dictionary approach documented on your help site. For changing themes, I clear the application merged dictionary then re-add the dictionaries for the new theme. This works fine, but for many of our controls we also need to apply other styles. We used the 'BasedOn' property of the style like below:

<Style TargetType="telerik:RadComboBox" BasedOn="{StaticResource RadComboBoxStyle}">
     <Setter Property="Padding" Value="5" />
</Style>

When the merged dictionary gets cleared and the new theme applied, it seems that some of these controls using BasedOn do NOT get updated properly. My guess would be that since it's a StaticResource, it will not get updated when the merged dictionary is reset.

Do you guys know of any workaround or a fix for this?

Thanks

3 Answers, 1 is accepted

Sort by
0
Vanya Pavlova
Telerik team
answered on 24 Feb 2014, 09:04 AM
Hi Niko,



Generally resources in a merged dictionary occupy a location in the resource lockup scope that is just after the scope of the main resource dictionary they are merged into. What you may do is to isolate these your custom styles in a separate resource dictionary and add it as the last one each time you change the theme. Let's say that you stored these styles in a file with name CustomStyles.xaml with following content:

                      xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Style TargetType="telerik:RadComboBox" BasedOn="{StaticResource RadComboBoxStyle}">
           <Setter Property="Padding" Value="5" />
     </Style>
</ResourceDictionary>

Then in your logic for switching the themes you may merge it, as follows:

foreach (string component in themeComponents)
{
    string fullName = String.Format("{0}.{1};{2}", baseName, themeName, component);
    Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary()
    {
        Source = new Uri(fullName, UriKind.RelativeOrAbsolute)
    });
      
}
Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary()
{
    Source = new Uri("CustomStyles.xaml", UriKind.RelativeOrAbsolute)
});

Then the styles contained in this custom resource dictionary will be evaluated each time you change the theme.

Regards,
Vanya Pavlova
Telerik
0
Niko
Top achievements
Rank 1
answered on 26 Feb 2014, 01:59 AM
Thank you, Vanya.

This seems to have solved my problem, but I'm still seeing an issue that is related. 

When the themes are changed at runtime, I clear the merged dictionaries and then re-add them similar to this: 
Application.Current.Resources.MergedDictionaries.Clear();
Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary() {
        Source = new Uri("/Telerik.Windows.Themes.Office_Black;component/Themes/System.Windows.xaml", UriKind.RelativeOrAbsolute)});
Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary() {
        Source = new Uri("/Telerik.Windows.Themes.Office_Black;component/Themes/Telerik.Windows.Controls.xaml", UriKind.RelativeOrAbsolute)});

This will work with mixed results. One out of three times, this code will hang my application. I see in Task Manager that my application's CPU usage will go up and down, yet the user interface is completely frozen.

Have you seen this or have any advice? Thank you
0
Vanya Pavlova
Telerik team
answered on 28 Feb 2014, 09:21 AM
Hi Niko,



Thank you for getting back to us! Actually we are not aware of a specific problem, increasing the CPU usage when switching implicit styles. I believe that the behavior you experience is a project specific.

Would it be possible to try to isolate the problem in a small repro project and send it to us as an attachment in a new support thread? 


I look forward to hearing from you! 


Regards,
Vanya Pavlova
Telerik
Tags
General Discussions
Asked by
Niko
Top achievements
Rank 1
Answers by
Vanya Pavlova
Telerik team
Niko
Top achievements
Rank 1
Share this question
or