Creating a SimpleCanvas
The first panel we’ll create is a simplified version of Canvas
called SimpleCanvas
. SimpleCanvas
behaves exactly like Canvas
, except that it only respects Left
and Top
attached properties on its children rather than Left
, Top
, and ZIndex
(and Right
and Bottom
in WPF).
Implementing SimpleCanvas
(or any other custom panel) consists of the following four steps:
1. Create a class that derives from Panel
.
2. Define any properties that would be useful for customizing layout, potentially including attached properties for the children.
3. Override MeasureOverride
and measure each child.
4. Override ArrangeOverride
and arrange each child.
Listing 20.1 contains the entire implementation of SimpleCanvas
in the context of a Windows ...
Get XAML Unleashed now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.