tags:

views:

501

answers:

2

As far as I know, everything done in XAML can be done in C#.

Why XAML is compiled in BAML and not in C# ? Wouldn't be more efficient to parse the XAML a compile-time and create the corresponding C# code ?

+3  A: 

The Xaml is separate from the c# code because it allows these elements to be "soft-coded." If you compile the Xaml to C# code, you defeat this characteristic, because now the UI elements, data binding, eventing, etc. are now hard-coded into the program, and you need to recompile the entire program to make a minor change to the user interface.

The blog post that petr k. references says that Xaml actually was compiled to IL at one time, but Baml is now used because:

  1. It is more secure (it cannot be executed directly), and
  2. Baml can be localized (different languages) without requiring recompilation.
Robert Harvey
+4  A: 

This blog post should provide a comprehensive answer: http://blogs.microsoft.co.il/blogs/tomershamam/archive/2007/05/25/Compiled-XAML-%5F3D00%5F-BAML-not-IL.aspx

petr k.
Thanks for the link, it gives good summary of the situation
Jalfp