XAML(eXtensible Application Markup Language) is an XML-based language, through which a developer can create rich UI easily and much more rapidly for WPF or Silverlight applications.
Anything that can be done in XAML can also be done in codebehind.
When we compile our WPF application in Visual studio, it compiles the XAML files into a compressed format called BAML (Binary Application Markup Language) and saves it to the assembly as resources with .BAML extension. On calling InitializeComponent() from WPF constructor, it will load the BAML file from assembly and create the object.
Some of the main advantages of BAML compared to traditional compilation (Intermediate Language) are:
• More secure, because it cannot be executed directly.
• BAML can be localized to be used in different languages .
• Size is very less and can be downloaded faster. So it can be used in XBAP applications
Loading a BAML file from BAML stream using reflection can be achieved as below:
var bamlReader = new Baml2006Reader(stream);
var xamlWriter = new XamlObjectWriter(bamlReader.SchemaContext);