开发者

ComponentResourceKey cannot be resolved when defining more than one

开发者 https://www.devze.com 2023-04-01 23:12 出处:网络
I have defined 3 styles in ResourceDictionary in external assembly like this: <Style x:Key=\"{ComponentResourceKey TypeInTargetAssembly={x:Type res:Common},

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号