代码之家  ›  专栏  ›  技术社区  ›  vanja.

将样式的TargetType属性设置为泛型类

  •  4
  • vanja.  · 技术社区  · 16 年前

    public class Selector<T> : Control { }
    

    然后在xaml中

    <Style x:TargetType="Selector">
    <Setter Property="MyProperty" Value="Green" />
    </Style>
    

    这不起作用,因为选择器缺少类型参数。

    3 回复  |  直到 14 年前
        1
  •  2
  •   QuantumHive An Nguyen    10 年前

    不能绑定到打开的泛型类型,如 List<T> List<Person> 通过定义占位符类型。

    C#

    class People : List<Person> {}
    

    XAML :

    <Style TargetType="{x:Type People}"> ... </Style>
    

    使现代化 :您需要指定 TargetType 这个 x:Key 属性,而不是两者。

        2
  •  1
  •   micahtan    16 年前

    here 关于可能有帮助的自定义标记扩展。

        3
  •  0
  •   user112889    16 年前

    我想你用的是普通WPF,不是Silverlight?如果我没弄错的话,你可以这样说:

    <Style TargetType="{x:Type Control}" x:Key="{x:Type Control}">
    </Style>