To know what to do with nested markup objects, the XAML analyzer will, among other things, consider whether the .NET class defines the default “content” property for use as a container for such children. This is done using the "ContentPropertyAttribute".
In your case, since I assume that you want nested objects to enter the grid, and since the children of the grid are part of the Children properties collection, you just need to do the following:
[ContentProperty("Children")] public partial class ElementType : Grid {
If you need to do some logic when adding children to your control (for example, only allow certain types to be children of your ElementType control), you can instead inherit from IAddChild and implement the AddChild and AddText methods.
Regarding the naming problem, it seems that only those who do not have control can have the names of children in the administrative field. That way, you can have the names of the children inside ElementType.xaml, but not named child elements in another markup where you create an instance of ElementType. I think this is because of how they optimize the logical tree or something like that. On the other hand, management without assistance is control only with code. Therefore, if you turn your class into a plain old empty Grid subclass, it works:
public class ElementType : Grid { }
Hooray! Less code!
Ludovic
source share