Knockout JS mappings

Knockout JS is a JavaScript library for creating MVVM JavaScript libraries. In a previous post I already showed some of the cool features of Knockout. http://marcofranssen.nl/knockout-that-cascading-dropdown/ If you want to spike your knowledge on Knockout a little more first, please visit Knockout’s documentation. In this article I want to zoom in on the Knockout mapping plugin. The Knockout mapping plugin enables you to easy map your JSON object into an observable JavaScript object. So here is a short example of what you’ll be able to do with it. So when you do an ajax request and receive a JSON result you can for example do the following. 12345678910111213141516var viewModel;// result could look like this: "{ "personId": 1, "firstName": "Marco", "lastName": "Franssen", "age": 26, "webpage": "http://marcofranssen.nl", "twitter": "@marcofranssen" }"$.ajax({ url: 'http://somewebpage.net/getPerson' type: 'GET', dataType: 'JSON', success: function (result) { var data = JSON.parse(result); viewModel = ko.mapping.fromJS(data); ko.applyBindings(viewModel, $('#person').get(0)); }, error: function (result) { //handle the error, left for brevity }});


Windows Phone Theme colors

When developing Windows Phone apps I love to use the theme accent colors in my apps. Since there are some new theme colors in Windows Phone 8 I started searching for their color codes. Lucky me I found them on msdn.aspx#BKMK_Implementation “Theme for Windows Phone”). Now you may be thinking how to use the colors in your own Windows Phone apps. The Color object doesn’t contain a color called Emerald. So I created a small class to help me out with this issue. First of all I created a small static helper method to convert the hexa colors to a color object. So we are able to put in the hexa color string and the function returns a color for us. 123456789public static Color FromHexa(string hexaColor){ return Color.FromArgb( Convert.ToByte(hexaColor.Substring(1, 2), 16), Convert.ToByte(hexaColor.Substring(3, 2), 16), Convert.ToByte(hexaColor.Substring(5, 2), 16), Convert.ToByte(hexaColor.Substring(7, 2), 16) );} Then I made some properties that caches the colors for us on their first use. The Color properties looks like this.