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

How to apply Theme ColorVariation for a specific control

3 Answers 466 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
ux
Top achievements
Rank 1
ux asked on 18 Apr 2018, 11:10 AM

Hello,

 

I am trying to make a change theme at runtime popup window. Inside the window, I list all the available themes and color variations, and when the user makes the selection, right below I have a little Panel which works like a Theme Preview, and I am applying the theme (removing and re-adding all theme related resource dictionaries) for that specific control. Everything is fine up to here, but when I try to use LoadPreset like;

VisualStudio2013Palette.LoadPreset(VisualStudio2013Palette.ColorVariation.Dark)

It changes all the application wide color variation/theme. I only want to apply that color variation to just that specific control. I could not see any overload of LoadPreset which takes the control as a input parameter. So how can I achieve this?

 

Thanks.

 

 

3 Answers, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 20 Apr 2018, 03:03 PM
Hello,

The theme palettes are designed as singletons which own all the properties that specify the looks of the current theme - colors, fonts, sizes etc. The LoadPreset method changes the values to these properties to a predefined set. Any changes to the singleton's properties result in creating, freezing and updating a resource in a thread-static resource dictionary that is merged on startup into the resource dictionaries for each of the assemblies. The applying of the resources is done via a DynamicResourceExtension to all the places they are needed. The theme palettes are only one instance and changing any of their properties applies to the whole application.

At this moment our themes do not provide out-of-the-box support for applying different theme variations per control instance. What you can do to achieve that is to create a resource dictionary and merge in it the needed resources. The resource key is of type VisualStudio2013ResourceKey and the values can be found from the palette, extracted at runtime or our documentation. The application of the resources, if the key is correct, should be handled from there by the theme's DynamicResourceExtension.

Regards,
Martin
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
ux
Top achievements
Rank 1
answered on 24 Apr 2018, 12:53 PM

Hello Martin,

Thanks for the reply. I understand the limitation for theme variations, but could not get the alternative solution you suggest. Could you please direct me with some tangible example.

 

Many thanks.

0
Martin
Telerik team
answered on 27 Apr 2018, 09:46 AM
Hello,

Please find attached as sample project where I demonstrate the approach that I mentioned previously via a custom ResourceDictionary that handles locally the resources that differ for each variation. This is not yet created as a SDK example, but we will be evaluating doing so in the future.

The same approach could be used for each of the themes with palettes and variations. If more themes are used, this could be abstracted and only one dictionary could be used in the resources of the parent element, whose contents could be only changed based on the variation or the theme chosen by the application logic.

I hope that this example would prove useful for your project. In case you have any other questions, please do not hesitate to contact us further.

Regards,
Martin
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
General Discussions
Asked by
ux
Top achievements
Rank 1
Answers by
Martin
Telerik team
ux
Top achievements
Rank 1
Share this question
or