Custom Development

Give XAML a Chance!

Chris Newham

Our beloved Javascript has come a long way since it's adoption as the programming language of the web nearly 20 years ago. It's evolved and changed to keep up with the ever-changing demand and trends of hosted applications on the web - and along with HTML and CSS, has been built deep within the web's foundation. But if we were to re-engineer HTML/CSS/Javascript on the web today, it would probably look a lot like XAML.

Where Does XAML Fit In?

XAML is not a web standard on the level of HTML/CSS/Javascript by any means, but simply a very well thought out XML-based presentation language that makes developing rich web applications easy to collaborate on. Typically used with a C# logic layer and MVVM pattern, a C# view model class binds to the XAML document at runtime using properties to update data much like a Javascript function binds to a HTML document with a "data-bind" attribute in the Knockout.js framework or "ng-bind" attribute in the Angular.js framework. The most notable advantage of XAML is that the structure, styling and UI behavior is done within the native XAML language while the application logic is maintained within the C# class.

Previously, XAML was only used in WPF for application development and Silverlight for web development, but it has been brought forward into the Windows Runtime (WinRT) for developing Windows 8 or Windows Store applications as an optional presentation language to choose from when starting a new project. Alternatively, Microsoft offers a Javascript syntax for WinRT applications using WinJS, a Javascript API layer for using the WinRT framework. This option uses a HTML document for structure (binding with the "data-win-bind" attribute) and a CSS document for styling. Because of the community support for Javascript (compared to the lack there of for XAML), developers using WinRT for the first time may be more likely to set their focus on building apps only with Javascript - but that may not always be the best idea...

Why Not Just Always Use Javascript When Building WinRT Applications?

One thing to note about using Javascript when building WinRT applications is that it is not transferrable to client-browser based Javascript - so if the thought is for cross-platform development, it won't work. Another concern (and one of my biggest complaints with Javascript in general) is how varied developer interpretations can be about the "standard" conventions in the web world. Everyone has their own coding style and can put a different amount of thought and care into the code's structure or presentation - and this is allowed by default in Javascript web applications. Bad habits from client-browser Javascript can easily be transferred into WinRT applications.

Using Javascript for WinRT applications will allow the same capabilities as using XAML /C# and it's a great way for web developers, who may be more familiar with HTML/CSS/Javascript, to break into WinRT features. But using XAML on a WinRT project can add just a little more of a focus on convention by allowing the developer team the opportunity to learn XAML/C# specific conventions while using a more consistent language across each presentation discipline and, in some ways, use the platform more as it was originally designed.

The Bottom Line...

This may not be much of a concern for small, single developer projects, but when there are multiple collaborators on a large, long-term project -- a little convention and code consistency can go a long way for future knowledge transfer and code maintainability. I've found XAML to be a fun and interesting language to learn and it has certainly exceeded my expectations. Whether you are a C# native or a traditional web language guru and are considering building a WinRT project, at least give XAML a try and see what you think -- you may be surprised by what it offers.

Chris Newham
ABOUT THE AUTHOR

Senior Technical Consultant