From bb57bfb88d19b034f5d139e6cc6720cd13917782 Mon Sep 17 00:00:00 2001 From: Nedyalko Nikolov Date: Tue, 12 May 2015 14:30:39 +0300 Subject: [PATCH] Fixed issue when UI element is bound to source different from bindingContext. --- apps/tests/ui/bindable-tests.ts | 22 ++++++++++++++++++++++ ui/core/bindable.ts | 3 ++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/apps/tests/ui/bindable-tests.ts b/apps/tests/ui/bindable-tests.ts index 51ce2c5b9..bd51b5741 100644 --- a/apps/tests/ui/bindable-tests.ts +++ b/apps/tests/ui/bindable-tests.ts @@ -490,4 +490,26 @@ export var test_BindingContext_NavigatingForwardAndBack = function () { } helper.navigateToModuleAndRunTest("./tests/ui/bindingContext_testPage1", null, testFunc); +} + +export var test_BindingToSource_FailsAfterBindingContextChange = function () { + var createLabel = function () { + var label = new labelModule.Label(); + return label; + } + var labelViewModel = new observable.Observable(); + var expectedValue = "testValue"; + labelViewModel.set("testProperty", expectedValue); + + var testFunc = function (views: Array) { + var testLabel = (views[0]); + testLabel.bind({ sourceProperty: "testProperty", targetProperty: "text" }, labelViewModel); + + var page = (views[1]); + page.bindingContext = new observable.Observable; + + TKUnit.assertEqual(testLabel.text, expectedValue); + } + + helper.buildUIAndRunTest(createLabel(), testFunc); } \ No newline at end of file diff --git a/ui/core/bindable.ts b/ui/core/bindable.ts index f5fc7465d..6a6bf0762 100644 --- a/ui/core/bindable.ts +++ b/ui/core/bindable.ts @@ -102,7 +102,8 @@ export class Bindable extends dependencyObservable.DependencyObservable implemen for (var p in this._bindings) { binding = this._bindings[p]; - if (binding.updating) { + var sourceIsNotBindingContext = (binding.source && (binding.source.get() !== oldValue)); + if (binding.updating || sourceIsNotBindingContext) { continue; }