Design time error while writing Nested type in xaml

≡放荡痞女 提交于 2019-12-08 02:43:46

问题


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 works 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?


回答1:


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.




回答2:


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>


来源:https://stackoverflow.com/questions/2278925/design-time-error-while-writing-nested-type-in-xaml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!