Nested type reference to ObjectDataProvider markup

I am trying to use a nested object in my ObjectDataSource a la this article . It doesn't seem to work for me.

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

      

+2


source to share


2 answers


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



While the XAML you write is clearly legal, runs at runtime, and loads correctly in Expression Blend, we do not currently believe that using and accessing nested classes from markup extensions is very common in building applications.

+2


source


One way to get around x:Type

nested type references is to define a new markup extension and use that instead of a markup extension x:Type

. I posted information about one such, including the source for the class Type2Extension

, in this answer .

Type2Extension

will not generate constructor errors like TypeExtension

. This may not be the case in VS 2010.



The only caveat is that the original TypeExtension

one you use with {x:Type

typename }

is slightly more robust than that Type2Extension

(e.g. checks if the arguments are null and throws exceptions).

+1


source







All Articles