3

I have this in Brushes.xaml:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:controls="clr-namespace:SkinBox.Controls">
    <SolidColorBrush x:Key="{x:Static controls:Keys.BackgroundBrushKey}"
                     Color="{DynamicResource {x:Static controls:Keys.BackgroundColorKey}}" />
</ResourceDictionary>

And use it like this in Generic.xaml:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:local="clr-namespace:SkinBox.Controls"
                    xmlns:system="clr-namespace:System;assembly=System">
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="pack://application:,,,/SkinBox.Controls;component/Themes/Skins/Blue.xaml" />
        <ResourceDictionary Source="pack://application:,,,/SkinBox.Controls;component/Themes/Brushes.xaml" />
    </ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

The problem is that wpf freezes the brush so the DynamicResource has no effect.

Is there a clean way to solve this? I can only think of nasty hacks.

Johan Larsson
  • 17,112
  • 9
  • 74
  • 88

1 Answers1

0

Thought of a workaround:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:controls="clr-namespace:SkinBox.Controls">
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="pack://application:,,,/SkinBox.Controls;component/Themes/Skins/Yellow.Colors.xaml" />
        <ResourceDictionary Source="pack://application:,,,/SkinBox.Controls;component/Themes/Brushes.xaml" />
    </ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

This still does not give true dynamic resources but it reapplies the brushes so that they update when applying the skin.

Removes the need for duplicating the brushes in every skin.

Johan Larsson
  • 17,112
  • 9
  • 74
  • 88