Unplanned
Last Updated: 29 Nov 2019 14:22 by ADMIN
ADMIN
Stefan Nenchev
Created on: 05 Jul 2016 08:12
Category: UI for WPF
Type: Feature Request
16
Themes - Enable resources modification through XAML

		
Duplicated Items
4 comments
ADMIN
Dilyan Traykov
Posted on: 29 Nov 2019 14:22

Hello everyone,

Thank you for your feedback.

One possible approach is to create attached properties for the theme's palette colors and apply them to any chosen DependencyObject in your application, for example, the MainWindow.

<Window x:Class="ChangePaletteSettingsPerControl.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
        xmlns:local="clr-namespace:ChangePaletteSettingsPerControl"
        local:MaterialThemeExtensions.PrimaryNormalColor="Red" 
        local:MaterialThemeExtensions.PrimaryHoverColor="SteelBlue" 
        local:MaterialThemeExtensions.PrimaryFocusColor="Green"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
The MaterialThemeExtensions class can, in turn, be defined as follows:
    public class MaterialThemeExtensions
    {
        public static Color GetPrimaryNormalColor(DependencyObject obj)
        {
            return (Color)obj.GetValue(PrimaryNormalColorProperty);
        }

        public static void SetPrimaryNormalColor(DependencyObject obj, Color value)
        {
            obj.SetValue(PrimaryNormalColorProperty, value);
        }

        public static readonly DependencyProperty PrimaryNormalColorProperty =
            DependencyProperty.RegisterAttached("PrimaryNormalColor", typeof(Color), typeof(MaterialThemeExtensions), new PropertyMetadata(OnPrimaryNormalColorPropertyChanged));

        private static void OnPrimaryNormalColorPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            MaterialPalette.Palette.PrimaryNormalColor = (Color)e.NewValue;
        }

        // ...
Using a similar approach, you can also define the theme palette's colors per control. An example of how to achieve this can be found in the "Change palette settings per control" demo from our SDK Samples Browser. The source code of the demo can be found in our GitHub repository.

Could you please give these approaches a try and let me know if any of them would work for you?

Regards,
Dilyan Traykov
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.
Georg
Posted on: 25 Nov 2019 11:24
absolutely necessary!
Antoine
Posted on: 11 Aug 2016 14:19
Indeed, for skinning purposes it would be better to have everything in XAML, including base fonts and colors.
Fabien
Posted on: 05 Jul 2016 09:06
It would be a plus to manage custom applications styles using noxaml binaries.