Aaron Drenberg
Aaron Drenberg

Reputation: 1117

Silverlight 4 Support for x:TypeArguments

I've got a generic base page class that I'd like to use with my Silverlight pages. The only problem is that the x:TypeArguments attribute doesn't seem to be working.

The attribute is only applied to the root element of the XAML page, and nowhere else.

The error message I keep getting from the compiler is: "Using the generic type 'Base.BasePage<T>' requires 1 type arguments". This error is always pointing to the generated Page.g.i.cs file.

Here is an example of what my root element looks like:

<Base:BasePage x:TypeArguments="ViewModels:MyViewModel">

I've had trouble finding good information on whether this is supported in Silverlight 4. Any help would be greatly appreciated. Thanks!

Upvotes: 4

Views: 1627

Answers (2)

andyshi
andyshi

Reputation: 157

This workaround only applies to WPF applications. Currently Silverlight does not support the x:TypeArguments property that is required in the deriving control’s XAML root tag.

If you must have Silverlight controls that derive from a generic base class you have to do some extra work. Basically you need to have an extra class in the middle so that the UserControl would derive from a non-generic class

Base class: public class GenericBase : UserControl

Middle class: public class MiddleStringControl : GenericBase

UserControl: public class UserControlWithGenericBase : MiddleStringControl

you may see this web page

deriving-from-a-generic-base-class

Upvotes: 0

Stephan
Stephan

Reputation: 5488

Unfortunately it isn't yet supported in Silverlight. If you want to include a class in XAML it can't be generic. You could still have a generic and add it to the Visual Tree from code, but not directly in the XAML.

Upvotes: 3

Related Questions