Layout system

Layout system is similar to WPF layout system. If you are unfamiliar with it, visit and pages. Main differences from WPF are:

But measuring and arrangement protocol is the same. So, if you want to create a custom control, you should read about measure and arrange in WPF.


Q. How to write a control that will use all available space?

You can assume that if you override MeasureOverride to return availableSize unmodified it will be right solution. But it will not. The fact is MeasureOverride can be called with infinity argument. But according to layout contract MeasureOverride can't return infinity. We should do next things. In MeasureOverride our control should return minimal required size to render itself. In ArrangeOverride control should return finalSize (without any changes). And in Render method control should use ActualWidth and ActualHeight to render content (it is right way for Render method in any case). And after that in constructor we should set default HorizontalAlignment and VerticalAlignment to Stretch.

How does it works ?

Button for example uses this method. See in debugger if you are struggling with it.