当前位置:   article > 正文

【SL学习】——嵌套元素(Nesting Elements)_nested element

nested element

【原文】 What the Grid does support is the ContentProperty attribute, which indicates the
property that should receive any nested content. Technically, the ContentProperty attribute is
applied to the Panel class, from which the Grid derives, and looks like this:

                     

[ContentPropertyAttribute("Children")]
public abstract class Panel : FrameworkElement

This indicates that any nested elements should be used to set the Children property.The
XAML parser treats the content property differently depending on whether or not it’s a collec-
tion property (in which case it implements the IList or IDictionary interface). Because the
Panel.Children property returns a UIElementCollection, and because UIElementCollection
implements IList, the parser uses the IList.Add() method to add nested content to the grid.

 

【自译】 Grid支持ContentProperty 属性(Grid没有IList 或者IDictionary),同时Grid所包括的子元素获得该属性。

着意味着任何嵌套的元素都可以被用作设置子元素属性。

 

 

 Grid.Children. Add(txtQuestion);

 VisualTreeHelper

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/110537
推荐阅读
相关标签
  

闽ICP备14008679号