I have defined 3 styles in ResourceDictionary in external assembly like this:
<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>
In the same assembly I have defined a class like this:
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");
开发者_如何学Python }
}
}
I use those styles like this:
<TextBox Style="{DynamicResource {x:Static segres:Common.NumbersOnly}}" />
This works if I define only one property in the class above, but if I define more than one (like above) resource cannot be resolved.
Why is this happening? This behaviour does not seem logical to me.
This is a bug in WPF with external dictionaries. It occurred in 3.5 and carried over to 4.0.
http://connect.microsoft.com/VisualStudio/feedback/details/553528/defaultstylekey-style-not-found-in-inner-mergeddictionaries
精彩评论