2

I'm trying to use a nested type in my ObjectDataSource a la this article. It doesn't seem to be working for me.

<ObjectDataProvider x:Key="myProvider" ObjectType="{x:Type local:OutsideClass+InsideClass}" MethodName="GetObjects" />
4

2 回答 2

2

This is a known issue in VS 2008 and beyond. Microsoft's official position is that you shouldn't be doing this:

Whilst the XAML you are writing is clearly legal, works at runtime, and loads in correctly in Expression Blend, we do not currently believe that use of and access to nested classes from Markup Extensions is very common in application building.

于 2009-08-18T19:43:07.120 回答
1

One way to work around x:Type references to nested types is to define a new markup extension and use it instead of the x:Type markup extension. I posted information about one such, including source for the Type2Extension class, in this answer.

The Type2Extension will not produce designer errors like the TypeExtension does. Perhaps this will not occur in VS 2010.

The only caveat is that the original TypeExtension you use with {x:Type typename} is a little more robust than Type2Extension (e.g., checking if arguments are null and throwing exceptions).

于 2009-08-18T20:24:18.017 回答