Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF: Can a Visual contain children?

Tags:

c#

wpf

The presence of an AddVisualChild method seems to imply that one can add a child visual to an object derived from Visual. If so, what is the purpose of the ContainerVisual`class?

like image 476
Tony the Pony Avatar asked Nov 14 '22 22:11

Tony the Pony


1 Answers

Most Visual derived classes allows for a single parent-child relationship in terms of visuals. By putting AddVisualChild within the Visual class, all Visual derived classes that allow for a child or children can use the same methodology and logic to manage their parent relationships.

ContainerVisual is intended for Visual implementations that allow for multiple children, via the Children property.

Visual, on the other hand, provides the plumbing to allow subclasses to expose a single child (Content), no content, or multiple Children using a uniform API.

like image 133
Reed Copsey Avatar answered Dec 14 '22 14:12

Reed Copsey