I am using DynamicResource in a template, and StaticResourceExtensions as resource inside each style using that template, so that the DynamicResource is evaluated differently in each of them them.
The problem is, I get this error:
Unable to cast object of type 'System.Windows.Media.Effects.DropShadowEffect' to type 'System.Windows.ResourceDictionary'
Here's my code:
<DropShadowEffect
x:Key="Sombra"
Opacity="0.5"
ShadowDepth="3"
BlurRadius="5"
/>
<ControlTemplate
x:Key="ControleGeometriaTemplate"
TargetType="{x:Type Control}"
>
<Border
x:Name="border"
Background="{TemplateBinding Background}"
Width="{TemplateBinding Width}"
Height="{TemplateBinding Height}"
/>
<Path
x:Name="ícone"
Fill="{TemplateBinding Foreground}"
Effect="{DynamicResource PathShadow}"
/>
</Border>
</ControlTemplate>
<Style x:Key="Bot?oGeometria" TargetType="{x:Type ButtonBase}">
<Setter Property="Template" Value="{StaticResource ControleGeometriaTemplate}"/>
</Style>
<Style
x:Key="Bot?oNavega??oBase"
TargetType="{x:Type ButtonBase}"
BasedOn="{StaticResource Bot?oGeometria}"
>
<Style.Resources>
<StaticResource x:Key="PathShadow" ResourceKey="Sombra"/>
</Style.Resources>
</Style>
See Question&Answers more detail:os