Derik Whittaker

Syndication

News


Leveraging your XAML MVVM Skills in HTML – Working with Observable Properties

This is a multi-part excerpt series from my PluralSight course Knockout for the XAML Developer 

knockout-xaml-developer

Knockout for the XAML Developer

The Knockout for the XAML developer course helps XAML developers, whether you’re a WPF or Silverlight developer, take their existing MVVM skills and transition them to the exciting world of HTML development.

This series is going to be broken down into 6 parts and should be enough show you show you can leverage your existing MVVM Skills you acquired while building XAML based and apply those to building HTML application with Knockout JS

Series Table of Context

  1. Setting up the Data Context
  2. Working with Observable Properties (this post)
  3. Working with Observable Arrays
  4. Handling User Click Events
  5. Handling Binding Context Changes
  6. Changing UI Appearances based on Bindings

 

Once we have our data context setup the next logic thing is to look at how to setup observable properties and bind them to UI elements.  When working in XAML applications you would setup your properties as seen below

How to setup observable properties in XAML

 image

The property above is pretty straight forward.  We have a string property which has a backing field and inside our Setter we are going to raise change notification for the given field to notify the UI that the display element needs to refresh to show the updated data.

Once we have our property setup we bind it to our UI elements as seen below

image 

How do we accomplish the same goal when using KnockoutJs?

How to setup the Observable Properties in Knockout Js

image

The image above is the 1 to 1 equivalent to setting up our observable property in Knockout

Breaking down this code (this code is in TypeScript).

  1. We first declared our observable property
  2. Next we need to initialize it, which we are doing with ko.observable()

Now that we have our property setup we need to bind it to our UI.  I can do this by using the knockout data-bind syntax as seen below

image

As you can see setting up your Observable Properties in Knockout is very similar to setting up the Observable Properties in a XAML based applications.

If you want to learn more about how your XAML MVVM skills transfer to HTML Development watch my Pluralsight Course – Knockout for the XAML Developer

Till next time,


Posted 08-11-2013 8:58 AM by Derik Whittaker
Filed under: ,

[Advertisement]

Comments

Derik Whittaker wrote Leveraging your XAML MVVM Skills in HTML – Working with Observable Arrays
on 09-03-2013 4:38 AM

This is a multi-part excerpt series from my PluralSight course Knockout for the XAML Developer  

Derik Whittaker wrote Leveraging your XAML MVVM Skills in HTML – Handling Click Events
on 10-10-2013 8:50 AM

This is a multi-part excerpt series from my PluralSight course Knockout for the XAML Developer  

Derik Whittaker wrote Leveraging your XAML MVVM Skills in HTML – Changing Binding Context
on 10-14-2013 5:30 PM

This is a multi-part excerpt series from my PluralSight course Knockout for the XAML Developer  

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Subscribe
Google Reader or Homepage

del.icio.us CodeBetter.com Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl CodeBetter.com Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of Devlicio.us
Red-Gate Tools For SQL and .NET

NDepend

SlickEdit
 
SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
LiteAccounting.Com
DevExpress
Fixx
NHibernate Profiler
Unfuddle
Balsamiq Mockups
Scrumy
JetBrains - ReSharper
Umbraco
NServiceBus
RavenDb
Web Sequence Diagrams
Ducksboard<-- NEW Friend!

 



Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers

 

Community Server (Commercial Edition)