views:

1362

answers:

3

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:

  1. The property 'Width' was not found in type 'NonGenericParent'.
  2. The property 'Height' was not found in type 'NonGenericParent'.
  3. 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.

A: 

Despite being at 2.0 silverlight (and especially the VS2008 tweaks for silverlight) are still very young. There are still quirks in the IDE stuff.

Do you still have the problem even after a sucessful build?

AnthonyWJones
The problem temporarily disappears after a build, and then once IntelliSense catches back up the error re-appears. On my dev workstation, that takes anywhere from a second to 20 seconds. I got excited a couple times thinking I had fixed the problem only to have it reappear after a long delay ;)
Chris Huseman
+1  A: 

Not sure about silverlight, but this compiles and runs as expected in c#:


class GenericObject[T] : UserControl
{
}

class StaticObject : GenericObject[Int32]
{
    public Int32 wide { get { return this.Width; } }
}

private void Form1_Load(object sender, EventArgs e)
{
    StaticObject so = new StaticObject();
    this.Text = so.wide.ToString();
}

So if it compiles against the clr, it should work just fine.

Could be just an intellisense bug as you're suggesting. Normally I'd advise against ignoring comiler warnings, but in this case it seems that the warning is not valid.

edit: substituted angle brackets with square brackets cause SO stripped them.

SnOrfus
I'd love to be able to just suppress this message, but I don't know how I'd go about doing that. It is actually an error according to IntelliSense and that is how it is displayed in the Error List window.
Chris Huseman
+3  A: 

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.

Chris Huseman