Add binding basic test pages.

This commit is contained in:
Vasil Chimev
2015-07-06 18:43:12 +03:00
parent 6b4fc789e3
commit 1f136e1e6d
5 changed files with 129 additions and 1 deletions

View File

@@ -0,0 +1,62 @@
import pageModule = require("ui/page");
import buttonModule = require("ui/button");
import textFieldModule = require("ui/text-field");
import stackLayoutModule = require("ui/layouts/stack-layout");
import observableModule = require("data/observable");
export function createPage() {
var page = new pageModule.Page();
var stack = new stackLayoutModule.StackLayout();
var sourceOneWay = new observableModule.Observable();
var sourceTwoWay = new observableModule.Observable();
var targetOneWay = new textFieldModule.TextField();
var targetTwoWay = new textFieldModule.TextField();
var buttonOneWay = new buttonModule.Button();
var buttonTwoWay = new buttonModule.Button();
// OneWay Binding
var bindingOptionOneWay = {
sourceProperty: "textSource",
targetProperty: "text",
twoWay: false
};
targetOneWay.bind(bindingOptionOneWay, sourceOneWay);
sourceOneWay.set("textSource", "OneWay");
buttonOneWay.on(buttonModule.Button.loadedEvent, function () {
buttonOneWay.text = sourceOneWay.get("textSource");
});
buttonOneWay.on(buttonModule.Button.tapEvent, function () {
buttonOneWay.text = sourceOneWay.get("textSource");
});
stack.addChild(targetOneWay);
stack.addChild(buttonOneWay);
// TwoWay Binding
var bindingOptionTwoWay = {
sourceProperty: "textSource",
targetProperty: "text",
twoWay: true
};
targetTwoWay.bind(bindingOptionTwoWay, sourceTwoWay);
sourceTwoWay.set("textSource", "TwoWay");
buttonTwoWay.on(buttonModule.Button.loadedEvent, function () {
buttonTwoWay.text = sourceTwoWay.get("textSource");
});
buttonTwoWay.on(buttonModule.Button.tapEvent, function () {
buttonTwoWay.text = sourceTwoWay.get("textSource");
});
stack.addChild(targetTwoWay);
stack.addChild(buttonTwoWay);
page.content = stack;
return page;
}