赞
踩
【原文】 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
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。