RichB asks:
What sort of layout does Avalon limit me to? Can I add my own layout engines instead of the standard flow layout?
Avalon doesn’t place any limits on layout, developers are free to write the layout algorithm of their choosing. How would you implement a custom layout? Well, first you’ll need a quick introduction to the Avalon layout APIs.
Layout computation occurs in two phases: Measure and Arrange; these functions are introduced on the UIElement base class. Measure and Arrange are the primary means for parent-child layout interaction (other interfaces exist, but they are optional). These passes can be (over) simplified as such:
- Measure: Parent asks child how much size it requires
- Arrange: Parent sets child size
This is easily illustrated with a simple element such as Image. The layout parent Measures the Image, which computes its “desired size” by reading the source file’s dimensions (say 100 x 100). The parent will later call Arrange to set the Image’s size, usually taking the Image’s desired size into account.
In most cases the child requires information about its layout context. A TextPanel with various paragraphs of text needs to know a line length to use when wrapping text, otherwise you end up with text which extends far off to the side of the screen. That is why Measure has a parameter, “available size,” which is commonly used as a wrapping size for flow layouts. Available size is usually the size of the window, getting partitioned as we descend the layout tree.
In summary:
- Measure: How much size is needed given this available size?
- Arrange: Set size
The Measure and Arrange concepts are the bare minimum you need to know for participating in layout. FrameworkElement introduces common properties such as Height, Width, MinHeight, MaxHeight, etc which add some complexity to the story, but you now have a basic understanding of the API.
Finishing Rich’s question:
...[W]ould I be able to plug a layout engine into Avalon which is capable of laying out the SQL Server ER Diagram - which lays out each table in a database connected via primary/foreign key relationships and arranged so that no entities overlap?
You can write your own custom element which implements such a layout algorithm, aside from the logic which ensures that no entities overlap, the code should be fairly simple.