【问题标题】:Assigning to an attached property using a child element使用子元素分配给附加属性
【发布时间】:2011-01-26 01:15:40
【问题描述】:

XAML 中的常规(未附加)属性可以指定为属性或子元素。

例子:

<TextBlock Foreground="Blue">Some text</TextBlock>

或者:

<TextBlock>
    <TextBlock.Foreground>
        <SolidColorBrush>Blue</SolidColorBrush>
    </TextBlock.Foreground>
    Some text
</TextBlock>

由于附加属性通常很简单,我只看到使用属性分配给它们的示例,例如:

<TextBlock Grid.Row="1">Some text</TextBlock>

但是是否可以使用子元素分配给附加属性?

我有一个自定义控件,它具有复杂(类)类型的附加属性。由于我无法在属性中指定值,因此我不确定如何从 XAML 分配给它。

【问题讨论】:

    标签: silverlight xaml attached-properties


    【解决方案1】:

    此功能称为property element syntax,是的,您可以使用元素属性语法设置附加属性:

    <TextBlock>
        <Grid.Column>1</Grid.Column>
            ABC
    </TextBlock>
    

    【讨论】:

      猜你喜欢
      • 2010-11-29
      • 2019-07-06
      • 1970-01-01
      • 2018-01-28
      • 2013-08-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-02
      • 1970-01-01
      相关资源
      最近更新 更多