This seems an old question: Why I can not reference StaticResource in App.xaml from a merged dictionary? Here is my code:
App.xaml:
<Application x:Class="WpfResources.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<Color x:Key="MyColor">GreenYellow</Color>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Dictionary1.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
Dictionary1.xaml:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<SolidColorBrush x:Key="Button.Static.Foreground" Color="{StaticResource MyColor}"/>
<Style TargetType="{x:Type Button}">
<Setter Property="Foreground"
Value="{StaticResource Button.Static.Foreground}"/>
</Style>
</ResourceDictionary>
At design time, everything is fine, I can see the foreground of button is set to MyColor. But at the run time, I got:
Exception: Cannot find resource named 'MyColor'. Resource names are case sensitive.
btw:these code work in UWP, but in WPF, something seems changed. I've done lots search on web and can not find an answer.
Any idea would be appreciated! thx!
(btw: I don't want to change to DynamicResource solution)
Edit: Why anyone give me a downgrade? any good reason? Although this is an 'old' question, but based on my search, it still has no proper answer!!