【问题标题】:WPF TextBox Property InheritanceWPF 文本框属性继承
【发布时间】:2015-03-26 11:23:45
【问题描述】:

为什么会这样:

<StackPanel TextBlock.FontWeight="Bold">
    <!-- All text boxes inside have their text in bold -->
    <TextBox Width="100" Height="24" Text="AaBbCc"  />
</StackPanel>

这不是吗?

<StackPanel TextBox.TextDecorations="Underline">
    <TextBox Width="100" Height="24" Text="AaBbCc"  />
</StackPanel>

error MC3015: The attached property 'TextBox.TextDecorations' is not defined on 'StackPanel' or one of its base classes.

但是FontWeight 属性也没有在StackPanel 上定义!那么为什么它们的行为不同呢?

【问题讨论】:

  • TextBlock.TextDecorations="Underline" 怎么样???您在第一段代码中使用了它。

标签: wpf dependency-properties attached-properties


【解决方案1】:

正如它所说 -- TextDecorations 不是 AttachedProperty !

如果你想将其应用于多个,还有其他方法,例如样式设置或使其成为模板

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-17
    • 1970-01-01
    • 1970-01-01
    • 2014-02-03
    • 1970-01-01
    相关资源
    最近更新 更多