views:

69

answers:

1

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:

  1. No validation, everything is done in concatenated strings. We all know this sucks

  2. 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.

  3. 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.

A: 

Maybe you dont need to build datatemplates in code. Do you really need to do that?

(#2) You dont need to include the xaml resource. it could reside remotely somewhere. all you have to do is load it remotely. But maybe im not understanding what you said.

AlvinfromDiaspar
Well that is one of the assumptions of the case, I really, really need to do that. Believe me, I'd love not to.
danijels