【问题标题】:Is there a good reason that Setter.Value isn't a ContentProperty?Setter.Value 不是 ContentProperty 有充分的理由吗?
【发布时间】:2009-05-06 08:25:52
【问题描述】:

每次我写出一个 Value 属性值不可内联描述的 setter 时,我都会诅咒 API 没有用 [ContentProperty("Value")] 标记 Setter 类的事实,这将允许这样做:

<Setter Property="BitmapEffect">
  <Setter.Value>
    <OuterGlowBitmapEffect GlowColor="#AAC" Opacity="0.2" GlowSize="1.25" />
  </Setter.Value>
</Setter>

...简化为:

<Setter Property="BitmapEffect">
  <OuterGlowBitmapEffect GlowColor="#AAC" Opacity="0.2" GlowSize="1.25" />
</Setter>

所以我的问题有点双重。首先,没有以这种方式配置 API 是否有充分的理由?其次,即使我不控制 WPF API,是否有任何事情阻止我以某种方式将这些元数据提供给 XamlReader

【问题讨论】:

  • ContentProperty 好点! 1up

标签: .net wpf xaml setter contentproperty


【解决方案1】:

在问了这个问题十年零十八天后,新开源的 WPF 提交了一个 PR 来解决这个问题:

https://github.com/dotnet/wpf/pull/745

【讨论】:

    【解决方案2】:

    确实不错...但是您可以轻松创建自己的从 System.Windows.Setter 继承的 Setter 类,将 ContentProperty 属性放在其上,然后使用它来代替标准 Setter。

    【讨论】:

      猜你喜欢
      • 2022-08-19
      • 2013-06-04
      • 2023-03-27
      • 1970-01-01
      • 2010-09-16
      • 2018-02-11
      • 2010-11-10
      • 2010-10-13
      • 1970-01-01
      相关资源
      最近更新 更多