WPF theming mechanism

4 posts, 0 answers
  1. Moyle
    Moyle avatar
    12 posts
    Member since:
    Jul 2017

    Posted 05 Aug Link to this post

    Hi,

    I've been reading as much as I can on how to theme controls.

    In particular, I wanted to react to this article:
    https://www.telerik.com/blogs/xaml-theming-implicit-styles-versus-stylemanager

    One of the cons that isn't mentioned for implicit styles, is that when you want to create a new style, you have to use BasedOn, otherwise nothing will be rendered.
    That is not what happens for regular WPF controls, because they still have their default (or theme) style applied. A custom style then only extend the default style, and if you want to disregard it altogether, you can set OverridesDefaultStyle to True.

    I have 2 questions:

    1. "Implicit styles for Telerik controls can’t be used if the application theme is set to other than the default Office_Black theme." => That is not something that I have observed. Using the 2019.2.510 Xaml packages, whichever theme I set is still honored when I create custom implicit styles. For example if I write this:
    <Style TargetType="telerik:RadButton">
        <Setter Property="FontWeight" Value="Bold" />
    </Style>
    Then the buttons will have a Bold text and still apply the rest of my current theme set by StyleManager, whether it's Office_Black, Office2016, Green or anything else.
    Could you explain what you meant, or if it is outdated and implicit styles are now supported with StyleManager?

    2. Why was support for the built-in WPF mechanism for theming not adopted? If in the AssemblyInfo.cs if your NoXaml assemblies you set ExternalAssembly for the first parameter of ThemeInfo, then it would be possible for your customers to create a Generic assembly (e.g. Telerik.Windows.Controls.Generic) that contains the Themes/Generic.xaml that merges whichever theme they choose, and even further customize the theme. And/or for customers who don't want to customize the themes, you could directly provide those Generic theme assemblies in packages for each theme. Therefore, you'd have the best of both worlds as to apply the theme, customers would only need to reference the appropriate Generic assembly, and they'd have implicit styling support without having to specify BasedOn on all their custom styles.

    Thanks in advance for any clarification

  2. Moyle
    Moyle avatar
    12 posts
    Member since:
    Jul 2017

    Posted 05 Aug in reply to Moyle Link to this post

    Sorry I meant the second parameter of ThemeInfo (genericDictionaryLocation), not the first.
  3. Moyle
    Moyle avatar
    12 posts
    Member since:
    Jul 2017

    Posted 05 Aug in reply to Moyle Link to this post

    I just did a bit more investigation on the second point, it would definitely have to be Telerik that creates those Generic theme assemblies, as they need to match on the version and, more importantly, the PublicKeyToken.

    I do have a hack that forces a generic theme dictionary from any arbitrary assembly, but it's not viable for serious business as it messes with private field through reflection of internal classes of the PresentationFramework assembly.
    Anyway, putting the hacky part aside, it does confirm that the mechanism works. That would mean no need for StyleManager, the possibility to use NoXaml binaries while having default styles applied, lifting the need to use BasedOn on all custom styles.

    For custom themes though, we would still need to use implicit styling, unless you provided unsigned NoXaml assemblies that would allow us to create our own matching theme assemblies.

  4. Vicky
    Admin
    Vicky avatar
    16 posts

    Posted 07 Aug Link to this post

    Hello Moyle,

    Thank you for your time and detailed investigation.

    The blog post that you refer to is written almost 6 years ago and therefore the containing information may not be up to date. In the meantime, a lot of improvements for both StyleManager and NoXaml have been made. The most frequently updated and recommended source of information is our live documentation - https://docs.telerik.com/devtools/wpf. You can check the following article and the whole Style and Appearance section as a further reference.

    About the first question that you asked, I confirm that implicit styles are fully supported when using the StyleManager theming mechanism. The snippet that you provided will work for all themes.

    About the second question, if I understand correctly, you need to create custom themes in a separate assembly. This can be achieved without using any theme dlls. We provide the XAML content of these dlls as separate XAML files. You can use them to base on an existing theme instead of starting from scratch, which will ensure that all the functionality works correctly. These files can be found in the /Telerik UI for WPF installation folder/Themes.Implicit folder. The following documentation article can be used as a further reference.

    To get started, you need to copy the needed XAML files in a separate folder in your application, make the needed modifications and (if desired) extract them in a separate theme assembly. You can also combine several themes in a single dll depending on your needs which will enable the possibility to easily change them at runtime.

    Thank you for the suggestions on improving the theming mechanism - we will definitely check them out. Yet, it will be of great help if you could share a sample project that demonstrates the approach you described.

    I hope that this will help you. If any further assistance is needed, do not hesitate to contact us.

    Best Regards,
    Vicky
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top