I wanted to write a Custom Control that would show a family tree… so i looked on FamilyShow….
So their control inherits FrameworkElement but then every thing gets super complex… are there any easy tutorials out there that show how to implement a custom FrameworkElement with children and so on?
Basically what i fail to do is this, Add child controls and show them, and when drawing getting the coordinates of the child controls…
What you are looking for is a
Panel: It already exposes aChildrenproperty of typeUIElementCollection, so all you need to do is add the children and override two methods:MeasureOverride computes the desired size of your panel. You can return whatever size you like. To take all the available space, just return the constraint:
ArrangeOverride computes the location of each child as a Rect. You can easily use attached properties to store additional data for each child. This can be publicly visible data such as DockPanel.Dock or Canvas.Top, or it can be private data you use to remember where everything goes and why. The skeleton for an ArrangeOverride is:
For drawing lines, you can either use child controls or simply override
OnRenderand draw lines directly into theDrawingContext.OnRenderis always called afterArrangeOverrideis complete and has access to the actual locations of the children.For detailed tutorials I would Bing “WPF Panel Tutorial” or “WPF Custom Panel Tutorial”. Here’s one that looked good.