立足A款关闭动态资源 [英] Basing A Style Off A Dynamic Resource

查看:87
本文介绍了立足A款关闭动态资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这似乎这样的事情是不允许的。任何解决办法

It seems something like this is not allowed. Any workaround?

  <Style x:Key=MyDerivedStyle TargetType="{x:Type Button}"
         BasedOn="{DynamicResource GlobalButtonStyle}" />       

  <Style x:Key="GlobalLabelStyle" TargetType="{x:Type Button}">



我得到的错误:
A'DynamicResourceExtension不能在'支持算法FMP设置类型'风格'的财产。 A'DynamicResourceExtension只能DependencyObject的一个的DependencyProperty进行设置。

I get the error: A 'DynamicResourceExtension' cannot be set on the 'BasedOn' property of type 'Style'. A 'DynamicResourceExtension' can only be set on a DependencyProperty of a DependencyObject.

如果我将其更改为静态资源,风格不会出现在我的控制。

If I change it to StaticResource, the style does not appear in my control.

推荐答案

下面两个问题:

首先,你的全局样式的需求出现派生样式之前(无论是在相同的资源部分,或试图定义派生的风格之前,在适当的ResourceDictionary合并。

First, your global style needs to appear before your derived style (either in the same resources section, or by merging in the appropriate ResourceDictionary before attempting to define the derived style.

此外,你需要明确NAME =btnOne
风格={StaticResource的:按钮X

Also, you need to explicitly define the Style in your button:

<Button x:Name="btnOne"
        Style="{StaticResource MyDerivedStyle}"
        Content="Derived" />

请注意,在这种情况下,你不准备创建动态资源(即,一个需要被重新装载),它是静态的,因为这是被用于一支持算法FMP需要一个样式

Note that in this case you aren't creating a Dynamic Resource (i.e. one that needs to be reloaded). It is static, as a Style that is being used for a BasedOn needs to be.

这篇关于立足A款关闭动态资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆