Not sure what I'm doing wrong here.
I have my Colors
defined in a ResourceDictionary
: Colors.xaml
:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Color x:Key="Normal">#FF404040</Color>
</ResourceDictionary>
Then used in Brushes.xaml
:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Colors.xaml"/>
<!-- here I may have more colors-->
</ResourceDictionary.MergedDictionaries>
<SolidColorBrush x:Key="Color" Color="{StaticResource Normal}" />
<!-- here I may have more brushes-->
</ResourceDictionary>
Then Brushes
are merged in Generic.xaml
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Brushes.xaml"/>
<!-- here I may have more resources-->
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
Now if I use the Brushes
in let say a Border
Style
like so :
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style x:Key="BorderContainer" TargetType="{x:Type Border}">
<Setter Property="Background" Value="{StaticResource Color}"/>
</Style>
</ResourceDictionary>
I must use it as DynamicResource
but if used as StaticResource
then I got this error at runtime :
{DependencyProperty.UnsetValue}' is not a valid value for property 'Background'
I wish to use StaticResource for Brushes everywhere in my app.