是否可以将 XAML 中样式的 TargetType 属性设置为通用类?
public class Selector<T> : Control { }
然后在 xaml
<Style x:TargetType="Selector">
<Setter Property="MyProperty" Value="Green" />
</Style>
这不起作用,因为 Selector 缺少类型参数。
是否可以将 XAML 中样式的 TargetType 属性设置为通用类?
public class Selector<T> : Control { }
然后在 xaml
<Style x:TargetType="Selector">
<Setter Property="MyProperty" Value="Green" />
</Style>
这不起作用,因为 Selector 缺少类型参数。
你不能绑定到一个开放的泛型类型List<T>
,但是你可以List<Person>
通过定义一个占位符类型来绑定到一个封闭的泛型类型。
C#:
class People : List<Person> {}
XAML:
<Style TargetType="{x:Type People}"> ... </Style>
更新:您要么需要指定样式的属性,要么需要指定属性,而不是两者。TargetType
x:Key
泛型在 XAML 中的支持非常有限。话虽如此,Mike Hillberg 有一篇关于自定义标记扩展的非常有趣的帖子,可能会有所帮助。
我认为您使用的是常规 WPF,而不是 Silverlight?如果我没记错的话,你可以这样说:
<Style TargetType="{x:Type Control}" x:Key="{x:Type Control}">
</Style>