This is a multi-part excerpt series from my PluralSight course 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
- Setting up the Data Context
- Working with Observable Properties
- Working with Observable Arrays
- Handling User Click Events
- Handling Binding Context Changes (this post)
- Changing UI Appearances based on Bindings
When building applications which use the MVVM pattern it is common to have deep view model. Working with a deep view model is not difficult but it becomes easier if we change change our binding context to remove some of the property chaining.
Take a look at the XAML below and notice how I am chaining the properties in my binding setup
In XAML this can be accomplished by setting the DataContext property on a given control as seen below:
Once you set the DataContext all child controls will have this set as their root context.
When working with Knockout you can accomplish the EXACT same result by utilizing the ‘with’ binder.
How to change Context Binding in Knockout
Take a look at the HTML markup below and notice who I am still using property chaining.
Now by using the ‘with’ binding in Knockout I can update my markup to look like below
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,
P.S. – Check out any one of my other Pluralsight courses
- InDepth Knockout Validation - Online Training Course for Developers
- HTML for the XAML Developer - Online Training Course for .NET Developers
10-14-2013 4:28 PM