Published
Thursday, July 19, 2007 4:39 PM
by
mtaulty
I've been building some bits with Silverlight V1.1 and there's a few things that keep cropping up in doing it.
The first is the idea of absolute layout.
When WPF first came on the scene you'd often hear people saying that Canvas and its absolute layout system is the least useful kind of layout and that you really want something a bit more dynamic with Grid being the ultimate example.
With Silverlight, this becomes apparent quite quickly and it's not particularly for me about building a complete UI but, instead, it's more about building controls.
If I decide to fix my whole UI so that it can't be sized in any way (including the Silverlight Full-Screen capability) then I don't feel too bad for my user. They can probably live with that choice.
However, if I want to build a control then it's almost certain that people will want to re-use my control with different sizes in different places and so the control needs to be capable of being resized (almost certainly at design time but equally likely at run time).
This means that the content of the control needs to be capable of being resized. Looking at the controls that Dave Relyea posted you can see that Dave has invented his own layout system for the controls in a similar manner to what goes on inside of WPF (i.e. we have a Measure and Arrange tap dance between a control and its container). Dave puts his Arrange and Measure onto an ILayout interface so that he can do his custom work.
Now, that works out nicely for Dave's controls but (AFAIK) it doesn't help if you want to mix in other bits that aren't from Dave's toolkit.
So far, I've ended up writing code that deals with layout rather than declaratively specifying layout and letting the layout system get on with it.
As an example, I was building a little control that looks like this;
so it's just a button made out of a couple of rectangles and a little Path for the arrow. However...when it comes to setting Width and Height on this control (once you've read the bottom part of the page here about shadowing inherited properties) essentially I have code which runs to resize both of the child rectangles and the path object. That is, the control has specific code for dealing with its specific content.
Now...that's kind of clunky but it's "fine" in the sense that I know at development time that my particular control only ever contains two rectangles and a path. The content is hard-coded but if it was a content control (e.g. just like the Button in WPF which accepts arbitrary content) then I'd need a better way of doing layout because at some point you do need that common Measure/Arrange style negotiation between a control and its container.
So...I think my top request for Silverlight V1.1 (so far) would be;
- A layout system that's common across the framework
Hopefully, Dave's work is the start of this being implemented in the framework rather than outside of it but that's just me hoping! :-)