How to apply Theme ColorVariation for a specific control

4 posts, 0 answers
  1. ux
    ux avatar
    10 posts
    Member since:
    Jun 2017

    Posted 18 Apr 2018 Link to this post

    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.

     

     

  2. Martin
    Admin
    Martin avatar
    126 posts

    Posted 20 Apr 2018 Link to this post

    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.
  3. ux
    ux avatar
    10 posts
    Member since:
    Jun 2017

    Posted 24 Apr 2018 in reply to Martin Link to this post

    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.

  4. Martin
    Admin
    Martin avatar
    126 posts

    Posted 27 Apr 2018 Link to this post

    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.
Back to Top