I’m trying to create a UserControl that inherits from a generic class. It does not directly inherit from a generic class, but through an intermediate class that does not use generics. This compiles and works at runtime, but I get an error at design time.
Here’s my generic parent class:
Public Class GenericParent(Of T) Inherits UserControl End Class
Here’s my non-generic parent class:
Public Class NonGenericParent Inherits GenericParent(Of String) End Class
Here’s my XAML:
<local:NonGenericParent x:Class='SilverlightApplication5.Page' xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' xmlns:local='clr-namespace:SilverlightApplication5' Width='400' Height='300'> <StackPanel> <Button Content='Hello'/> </StackPanel> </local:NonGenericParent>
The IntelliSense parser gives the following errors:
- The property ‘Width’ was not found in type ‘NonGenericParent’.
- The property ‘Height’ was not found in type ‘NonGenericParent’.
- The type ‘NonGenericParent’ does not support direct content.
It is as though IntelliSense can’t see up the inheritance tree past the GenericParent class. I’ve tried specifying the ContentPropertyAttribute directly on the SilverlightApplication5.Page class, the NonGenericParent class, and it does not work.
I’ve read that the TypeArguments attribute is not supported in Silverlight 2.0. That is why I’ve created the intermediate NonGenericParent class.
If anybody has any ideas how to silence these errors I’d be eager to hear them.
Update: We’ve opened a support ticket with MSFT, I’ll update this with whatever their solution is.
We’ve received word from Microsoft that this is not likely to be fixed in future versions. After they bounced the problem around trying to find the responsible group, it appears that this problem belongs to their WPF developer group, which is where the ‘not going to fix it’ answer came from.
In the meantime, we’ve updated our code to yank out the generics from the parent classes until I guess XAML 2009.