XAML Markup Extensions

Summary

The aim of this project is to improve the capabilities of XAML code while keeping an eye on a good XAML code readability. This covers the developement of useful XAML markup extensions for Silverlight (SL) and the Windows Presentation Framework (WPF) as well as helper classes to extend their scope of operation.

This project is and will be free for everyone to use. This also implies that any contribution to it is welcome. Thus, feel free to create your own fork on GitHub (refer to links section below).

Good news: The library now partially supports design time for Silverlight!

Content

Improved markup extension nesting


This project offers a straightforward solution to the problem that you don't know where you are in case of a nested markup, giving you the advantage to exactly control the output of your markup extension depending on the nesting tree, thus extremely expanding their application range. It's very easy to implement, even if you never built markup extensions before.

Take a look at this sample (coming soon) for a demonstration.

Feature summary

  • Each markup extension knows its nesting subtree (downto each dependency object)
    • During runtime and designtime
    • Multiple branches possible
    • Markup extension (trees) can be declared as resources to reduce memory and calculation overhead
  • ProvideValue is replaced by a function delivering the particular endpoint information
  • Notification engine to update the whole nesting tree if needed
  • Support of List objects
  • Interface for existing markup extensions included

Why?

Markup extensions are not able to resolve their target dependency object when nested into each other. This restricts their usage to a small application range, because useful information such as the types of the target object and property as well as the content of additional attached or inherited properties could not be read out in order to adopt the own result to the particular situation.

Therefore, a new markup extension base class derived from the WPF MarkupExtension class was developed. In this class, the whole nesting tree is properly tracked during the ProvideValue function that is called by the XAML parser at designtime or runtime. This enables each markup extension in the tree to adopt its output to each endpoint (the target dependency object) of its subtree including multiple branches caused by markup extensions referenced as a resource.

Localization


With the help of the nesting feature, the WPF Localization Extension was enhanced. Please refer to the homepage and the latest GitHub commits of this project for further information.

String operations

  • Concatenate extension
    • Concatenate a list of strings (or markup extensions delivering these strings)
    • Provide a format code to control the output

Design

  • Alternating grid color extension
    • Apply an alternating color to rows of a grid.

Under developement

  • Dynamic binding extension - allows changes of Source and Path
  • Aspect ratio extension - bind width and height of a control while keeping a particular aspect ratio

Where can I get it?

View up-to-date source at GitHub:
https://github.com/MrCircuit/XAMLMarkupExtensions

A NuGet package is also available:
https://www.nuget.org/packages/XAMLMarkupExtensions

Supported Platforms

  • WPF .NET 3.5
  • WPF .NET 4.x
  • SL 5.0

Last edited Apr 7, 2013 at 11:08 PM by MrCircuit, version 17