Hi
This might be more of an outcry, but building DataTemplates in Silverlight code seems to be impossible. The one option I am aware of being using XamlReader.Load(string), one is met with several issues using this approach:
No validation, everything is done in concatenated strings. We all know this sucks
Any necessary resources have to be included, as this will run in its own context. This also sucks, although there is a logical explanation and not a show-stopper.
Any attempts to include event calls inside your DataTemplate will fail with InvalidOperationException: Invalid XAML for control: XamlReader.Load() does not accept event handlers.
No.3 seems to be a show-stopper for me. I would appreciate it if anyone gave some clues, pointers or ideas towards another / better way of doing this.
In WPF there is a FrameworkElementFactory that can provide assistance, however there seems to be no remedy for this in Silverlight.