First off, is there any list of properties that can be set when using data-win-bind attribute in your markup?
A few things I am looking to do:
- Conditionally append a classname based on the datasource.
- Declare event listeners within the markup. Would like these event listeners to exist on the datasource and NOT some global function.
There are two sets of properties that you can bind to.
The first is the properties supported in the DOM by each element type. So, for an
imgelement, for example, you can bind thesrcproperty to set the image that is displayed. For aninputelement you can bind to thevalueproperty. You can see a complete list of the HTML elements that are available for Metro apps here.The second set of properties is available if you have applied a WinJS UI control to an element (which is usually done with the
data-win-controlattribute. You can set the properties defined by each control via thewinControlproperty which is added when the control is applied. As an example, if you wanted to bind theitemTemplateproperty in aListView, you would have markup like this:You can use the same technique to set your event handlers. Define the callback functions as part of your data source like this:
And then bind to the
on*property that corresponds to the event you are interested in:Adding and removing individual classes is much trickier. I find that the easiest way to do it is with a code-based binding. Create an observable property in your data source like this:
And then use the bind method on the observable object to get notifications when the value changes and apply/remove the class, as follows:
You can bind classes declaratively, but you need to set all of the classes in one go, which is rarely that useful. If you want to go that approach, then you bind the
classNameproperty on the element.