Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Panel.Children vs Panel.InternalChildren -- What's the difference?

According to MSDN - Panel.InternalChildren Property:

Classes that are derived from Panel should use this property, instead of the Children property, for internal overrides such as MeasureCore and ArrangeCore.


So, this is really a 2 part question:

  1. If I create a Panel of my own, FooPanel, which derives from Panel, I can't seem to override MeasureCore or ArrangeCore. I'm not sure why that statement is even there. I can, however, override MeasureOverride and ArrangeOverride. So, I wonder if I still need to use the InternalChildren property for these 2 methods.

  2. What is the real difference between the Children property and the InternalChildren property?

like image 522
myermian Avatar asked Apr 07 '11 15:04

myermian


2 Answers

  1. You would override MeasureOverride and ArrangeOverride, that must be a mistake in the documentation, or intended for internal Microsoft employees. The MeasureCore and ArrangeCore are sealed by FrameworkElement, so you can't override them.

  2. The Children property is public and simply calls InternalChildren, which is protected. So either is probably safe, since Children would get inlined.

MSDN says otherwise ( http://msdn.microsoft.com/en-us/library/ms754152.aspx) but the documentation is wrong. (use reflector to see that the implementation of Children simply calls InternalChildren)

like image 121
CodeNaked Avatar answered Sep 24 '22 00:09

CodeNaked



EDIT: As CodeNaked corrected - MSDN docs are in fact incorrect. InternalChildren and Children are the same.

Using reflector, you can see the implementation of Children which is public UIElementCollection Children { get { return this.InternalChildren; } }. So unless there is some voodoo going on, they are the same.


Children are just children that were added regularly, whereas InternalChildren includes children that were added through data binding (when the panel is the ItemsPanelTemplate)

"Children represents the child collection of elements that the Panel is comprised of. InternalChildren represents the content of the Children collection plus those members generated by data binding. Both consist of a UIElementCollection of child elements hosted within the parent Panel."

see http://msdn.microsoft.com/en-us/library/ms754152.aspx

like image 31
Elad Katz Avatar answered Sep 24 '22 00:09

Elad Katz