Dynamically generating content controls

One of the most popular features of Open XML among developers is the concept of binding content controls (structured document tags) to custom XML nodes. This is a powerful concept that allows for simple integration between existing XML instances of business data and the rich look and feel of typical Open XML word-processing documents, while keeping the data and presentation details cleanly separated.

Once developers start thinking creatively about how to use content controls, however, there’s one thing that can get a bit confusing: how to deal with repeating data structures. It’s a simple matter to have a fixed set of content controls bound to a fixed set of custom XML nodes, but in many scenarios you’ll want to generate a document with a table that contains a variable number of rows, to be determined dynamically at runtime by the data itself.

My colleague Dimitris Koutsanastasis, a developer evangelist in Greece, has put together an interesting demonstration of how to handle this situation over on OpenXmlDeveloper.org entitled “Dynamic production of repeating context controls by a WCF service.” It’s packaged as a WCF service with a Winform front end, but the underlying architecture is applicable to any scenario where you need to dynamically generate content controls. The article contains complete source code.

Comments (0)