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" />
source to share
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.
source to share
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).
source to share