Referencing Nested Type in Visual Studio 2008 XAML Designer
With the following resource definition
<ObjectDataProvider MethodName="GetValues" ObjectType="{x:Type sys:Enum}" x:Key="AccountTypeValues">
开发者_开发百科 <ObjectDataProvider.MethodParameters>
<x:Type TypeName="domain:Account+AccountType" />
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
the designer complains that "Type 'Account+AccountType' was not found." However, the nested type exists and code complies and runs without a problem. Since the designer thinks the XAML is incorrect, it won't display a graphical rendition of the XAML.
What do I need to do to get the designer to recognize Account+AccountType as valid? I'd really like the visual part of the designer to work.
Thank you, Ben
It looks like this is a known bug in Visual Studio. From http://social.msdn.microsoft.com/forums/en-US/wpf/thread/12f3e120-e217-4eee-ab49-490b70031806/:
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.
See also http://connect.microsoft.com/VisualStudio/feedback/details/361509/xaml-designer-cannot-handle-typename-with-nested-classes.
You could create a static property that calls Enum.GetValues(typeof(Account.AccountType))
and bind to that instead of using an ObjectDataProvider
. Or, if you control the types, you could move the enum outside the class.
精彩评论