Silverlight Printing and Inheritance of Language Settings

From what I learned, printing in Silverlight (4) is straight forward: Create a control and print it.

I used this pattern in a Silverlight application I built. Because I had to implement some multipage- and list handling, I created user controls that I added into a stack panel of the main print control during runtime (inside of the PrintDocument.PrintPage event handler).

To get the correct – current UI culture dependent – formatting of all of the date and numeric values when printed, I set the Language property in the ctor of the main print control to the current culture’s language. But when the child controls were printed, the culture-dependent output was formatted in en-US style, not in the current culture style. I had to set the Language property inside of each child control.

Of course, at the time the child control was created using new ChildControl, the Language property could not be set to the value of the parent, since at that time the child did not know it has one. But I expected Silverlight to change the Language property to the parent’s value as soon as the child as added to the Children collection.

Well, adding Language = XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.Name) ; into each child control’s ctor (or into the base class’ ctor), wasn’t that hard to do 😉