我在外部程序集中的ResourceDictionary中定义了3种样式,如下所示:
<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>在同一个程序集中,我定义了一个类,如下所示:
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");
}
}
}我像这样使用这些样式:
<TextBox Style="{DynamicResource {x:Static segres:Common.NumbersOnly}}" />如果我在上面的类中只定义了一个属性,但如果我定义了多个(类似上面的)资源,那么就不能解析资源。
为什么会发生这种情况?对我来说,这种行为似乎不符合逻辑。
发布于 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
https://stackoverflow.com/questions/7271084
复制相似问题