相关疑难解决方法(0)

在 Style.Resources 中使用 StaticResourceExtension 时出错

我在模板中使用 DynamicResource,并在使用该模板的每个样式中使用 StaticResourceExtensions 作为资源,以便在每个样式中对 DynamicResource 进行不同的评估。

问题是,我收到此错误:

Unable to cast object of type 'System.Windows.Media.Effects.DropShadowEffect' to type 'System.Windows.ResourceDictionary'
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

<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>
Run Code Online (Sandbox Code Playgroud)

wpf xaml resourcedictionary dynamicresource

0
推荐指数
1
解决办法
923
查看次数

标签 统计

dynamicresource ×1

resourcedictionary ×1

wpf ×1

xaml ×1