Friday, July 21, 2006

Writing a Dock Panel System in .NET 3.0

So... I’ve just completed a dockable windows toolkit for our Aurora product. I thought I would share the details.

Initially, I thought it would take about 3 weeks. We had one developer take a stab at it, but it was so buggy and spaghetti-ish we did a rewrite.

The end result was pretty cool, and took about 1/3 of the code of the first attempt. We can dock panels inside panels that are floating or panels that are docked. We can add the panels such that they are children in a grid or merge the panels so that they are children in a tab control. We can dock on all four sides of our window and serialize out the last state and position of the individual panels. We have a control template written such that we can specify tabs on either top and bottom or left and right.

Overall, the .NET 3.0 API was perfect for this. It is so easy to take the content off of a tab control, for example, and apply it to a floating window. But ... it wasn’t without its difficulties. The Grid control was a complete pain. We tried a Dock Panel initially but it didn’t resize very well. The Grid resizes better, but when you collapse a panel in a cell in a Grid, the GridSplitter doesn’t handle fixed size objects very well. When we set a cell size to Auto, the Gridsplitter wouldn’t behave as desired for our requirements. This was a major hurdle that resulted in having to hook the GridSplitter delta change events and managing the size of the grid cells manually, often switching between grid cell length types that were ‘pixel’ and those that were ‘star’. The other problem we hit was getting the mouse position - it was often invalid or inaccurate if we were in the middle of a MouseCapture or Window.DragMove.

The end result is pretty neat. Check it out in the latest build of the Aurora XAML Designer on our Web site ...

0 Comments:

Post a Comment

<< Home