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 at compile-time and create the corresponding C# code ?
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 at compile-time and create the corresponding C# code ?
This blog post should provide a comprehensive answer: http://blogs.microsoft.co.il/blogs/tomershamam/archive/2007/05/25/Compiled-XAML-3D00-BAML-not-IL.aspx
In theory, all XAML can be compiled to the equivalent C# (although BAML is used in practice).
Check out the XAML Code Behind Generator at http://xamlgenerator.codeplex.com/.
Its a plugin for Visual Studio 2010 that allows you to compile XAML into the equivalent C#, its really interesting to get a feel for how XAML is compiled into C#.
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: