Tesseract & TIM Enhancements (Ribbon Example)

Over the past few days I've added some new features to both Tesseract & TIM, as well as fixed a few bugs & changed a few things around. The result? much cleaner markup. Previous posts have introduced a couple of ways to clean up markup, such as inheritance & include statements, and inheritance in particular has continued to be improved with new enhancements.

When a control is defined as inheriting from something else, that something else can now redirect all of the controls children defined in the markup to a child it defines itself. This is useful for example if you need to put all the children of a control into a list on the original control (as is done in the example below), allowing the controls to be arranged nicely without manually setting positions. This is done using the "RedirectChildren" attribute, with the value being the (zero based) index of the child to redirect to.

User types are a new addition, allowing you to specify a type name from a base type and optionally an inheritance value. The base attribute requires a prefix specifying the namespace of the base type. So, if you have a lot of controls of the same type which inherit from the same thing, you can define a user type from the common base type & inheritance value, then define your controls beginning with <MyTypeName. A simple example of defining a user type:

<Type Name="MyBtn" t:Base="Button" Inherit="btnBase">

<MyBtn Text="1"/>
<MyBtn Text="2"/>
<MyBtn Text="3"/>

The above will result in 3 buttons, each inheriting from btnBase, which could (for example) change the background of the button or increase the text size, allowing you to specify a design only once & reuse it many times, and to change the design only once to affect all 3 buttons.

There are other various general cleanups in the markup, which will be apparent in the attached markup files (particularly when compared with those from previous posts), but now lets look at a practical use for these features:

The above is a appears simple but has a relatively complex structure upon closer inspection. The window contains a TabControl, which contains 4 TabPages, each of which contains a List to arrange children horizontally. The first tab contains 2 panels, each of which contains a further panel & label aligned to its bottom. The window also contains 2 buttons. Add to this the fact that style properties of every control have been changed, and without using any inheritance, includes or user types the markup would be huge & pretty hard to read. However, using these features the markup can be split into 2 files, 1 for generic definitions that can be reused throughout this (and other) GUIs (Office2K7.xml), and 1 which contains the GUI itself (Office2K7Test.xml). Both of these markup files are attached, and it is clear by reading through them just how handy some of the newer features in Tesseract (and TIM in particular) are.