WPF TextBox属性继承

时间:2015-03-26 11:23:46

标签: wpf dependency-properties attached-properties

为什么会这样:

<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属性!那他们为什么表现得不一样呢?

1 个答案:

答案 0 :(得分:2)

正如它所说 - TextDecorations不是AttachedProperty!

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