我正在尝试创建一个继承自泛型类的 UserControl。它不是直接继承自一个泛型类,而是通过一个不使用泛型的中间类。这在运行时编译并工作,但在设计时出现错误。
这是我的通用父类:
Public Class GenericParent(Of T)
Inherits UserControl
End Class
这是我的非泛型父类:
Public Class NonGenericParent
Inherits GenericParent(Of String)
End Class
这是我的 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>
IntelliSense 解析器给出以下错误:
- 在“NonGenericParent”类型中找不到属性“Width”。
- 在“NonGenericParent”类型中找不到属性“Height”。
- “NonGenericParent”类型不支持直接内容。
就好像 IntelliSense 无法查看 GenericParent 类之后的继承树。我尝试直接在 SilverlightApplication5.Page 类、NonGenericParent 类上指定 ContentPropertyAttribute,但它不起作用。
我读过 Silverlight 2.0 不支持 TypeArguments 属性。这就是我创建中间 NonGenericParent 类的原因。
如果有人对如何消除这些错误有任何想法,我很想听到它们。
更新:我们已经向 MSFT 开了一张支持票,无论他们的解决方案是什么,我都会对其进行更新。