开发者

Design time error while writing Nested type in xaml

I have created a usercontrol which accept type of enum and assign the values of that enum to a ComboBox control in that usercontrol. Very Simple. I am using this user control in DataTemplates. Problem comes when there comes nested type. I assign that using this notation

EnumType="{x:Type myNamespace:ParentType + NestedType}"

It wo开发者_如何学Gorks fine at runtime. but at design time it throws error saying

Could not create an instance of type 'TypeExtension'

Why? Due to this I am not able to see my window at design time. Any help?


According to this post You need to make use of the capabilities the MarkupExtension class provides.

however there is another way around it:

<ObjectDataProvider 
    MethodName="GetValues"
    ObjectType="{x:Type sys:Enum}"
    x:Key="NestedEnumDataProvider">
    <ObjectDataProvider.MethodParameters>
        <x:Type TypeName="myNamespace:ParentType+NestedType"/>
    </ObjectDataProvider.MethodParameters>
</ObjectDataProvider>


According to Rob Relyea form Microsoft this is a defect within the VS2008/2010 designer.

We had somebody look at the use of {x:Type Foo+Bar} pattern and test it in VS2010 and Blend4. It appears that it works fine at Runtime, CompileTime, in Blend 4, but fails in VS2010's WPF Designer.

We've filed a bug, and routed it to the WPF Designer team.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜