BAML vs XAML

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);
while(bamlReader.Read())
{
xamlWriter.WriteNode(bamlReader);
}
return xamlWriter.Result;

Leave a Reply

Your email address will not be published. Required fields are marked *


7 − = three

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>