首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >定义多个时无法解析ComponentResourceKey

定义多个时无法解析ComponentResourceKey
EN

Stack Overflow用户
提问于 2011-09-01 21:34:20
回答 1查看 489关注 0票数 0

我在外部程序集中的ResourceDictionary中定义了3种样式,如下所示:

代码语言:javascript
复制
<Style x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type res:Common},
ResourceId=numbersOnly}" TargetType="TextBox">
...
</Style>

<Style x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type res:Common},
ResourceId=positiveInt}" TargetType="TextBox">
...
</Style>

<Style x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type res:Common},
ResourceId=positiveDecimal}" TargetType="TextBox">
...
</Style>

在同一个程序集中,我定义了一个类,如下所示:

代码语言:javascript
复制
public static class Common {
        public static ComponentResourceKey NumbersOnly {
            get {
                return new ComponentResourceKey(
                typeof(Common), "numbersOnly");
            }
        }
        public static ComponentResourceKey PositiveInt {
            get {
                return new ComponentResourceKey(
                typeof(Common), "positiveInt");
            }
        }
        public static ComponentResourceKey PositiveDecimal {
            get {
                return new ComponentResourceKey(
                typeof(Common), "positiveDecimal");
            }
        }
    }

我像这样使用这些样式:

代码语言:javascript
复制
<TextBox Style="{DynamicResource {x:Static segres:Common.NumbersOnly}}" />

如果我在上面的类中只定义了一个属性,但如果我定义了多个(类似上面的)资源,那么就不能解析资源。

为什么会发生这种情况?对我来说,这种行为似乎不符合逻辑。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-09-02 01:12:32

这是使用外部字典的WPF中的一个错误。它出现在3.5,并延续到4.0。

http://connect.microsoft.com/VisualStudio/feedback/details/553528/defaultstylekey-style-not-found-in-inner-mergeddictionaries

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7271084

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档