Vale
Vale

Reputation: 3298

ComponentResourceKey cannot be resolved when defining more than one

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");
            }
        }
    }

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.

Upvotes: 0

Views: 522

Answers (1)

tsells
tsells

Reputation: 2771

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

Upvotes: 1

Related Questions