Assigning to an attached property using a child element
Regular (not attached) properties in XAML can be assigned either as an attribute or as child element.
Example:
<TextBlock Foreground="Blue">Some text</TextBlock>
Or:
<TextBlock>
<TextBlock.Foreground>
<SolidColorBrush>Blue</SolidColorBrush>
</TextBlock.Foreground>
Some text
</TextBlock>
Since attached properties are usually simple, I only see examples of assigning to them using开发者_运维知识库 an attribute, example:
<TextBlock Grid.Row="1">Some text</TextBlock>
But is it possible to assign to an attached property using a child element?
I have a custom control that has an attached property of a complex (class) type. Since I can't specify the value in an attribute, I'm not sure how to assign to it from XAML.
This feature is called the property element syntax and yes, you can set attached properties using the element attribute syntax:
<TextBlock>
<Grid.Column>1</Grid.Column>
ABC
</TextBlock>
精彩评论