Silverlight 4 support for x: TypeArguments

I have a common base page class that I would like to use with my Silverlight pages. The only problem is that the x: TypeArguments attribute is not working.

The attribute applies only to the root element of the XAML page and nowhere else.

The error message I get from the compiler is: "Using the generic type 'Base.BasePage<T>' requires 1 type arguments" . This error always points to the generated Page.gics file.

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

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

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

+4
source share
2 answers

Unfortunately, it is not yet supported in Silverlight. If you want to include a class in XAML, it cannot be shared. You can still have one in common and add it to the visual tree from code, but not directly in XAML.

+3
source

This workaround applies only to WPF applications. Silverlight does not currently support the x: TypeArguments property, which is required in the generation of the XAML root tag control.

If you must have Silverlight controls that are based on a base base class, you need to do more work. Basically you need to have an extra class in the middle so that UserControl comes from a non-generic class

Base class: public class GenericBase: UserControl

Middle class: public class MiddleStringControl: GenericBase

UserControl: public class UserControlWithGenericBase: MiddleStringControl

you can see this web page

deriving-from-a-generic-base-class

0
source

All Articles