Merge pull request #434 from NativeScript/nnikolov/ListViewBindingContextIssue

BindingContext set two times on adding item to ListView. Fixed issue #410.
This commit is contained in:
Vladimir Enchev
2015-07-16 09:42:05 +03:00
4 changed files with 46 additions and 4 deletions

View File

@@ -829,9 +829,7 @@ export class View extends proxy.ProxyObject implements definition.View {
* Method is intended to be overridden by inheritors and used as "protected"
*/
public _addViewCore(view: View) {
view._setValue(bindable.Bindable.bindingContextProperty, this.bindingContext, dependencyObservable.ValueSource.Inherited);
view._inheritProperties(this);
this._propagateInheritableProperties(view);
view.style._inheritStyleProperties();
@@ -845,7 +843,11 @@ export class View extends proxy.ProxyObject implements definition.View {
}
}
private _inheritProperties(parentView: View) {
public _propagateInheritableProperties(view: View) {
view._inheritProperties(this);
}
public _inheritProperties(parentView: View) {
var that = this;
var inheritablePropertySetCallback = function (property: dependencyObservable.Property) {
if (property instanceof styling.Property) {

2
ui/core/view.d.ts vendored
View File

@@ -409,6 +409,8 @@ declare module "ui/core/view" {
isLoaded: boolean;
_addView(view: View);
_propagateInheritableProperties(view: View)
_inheritProperties(parentView: View)
_removeView(view: View);
_context: android.content.Context;

View File

@@ -114,6 +114,7 @@ export class ListView extends view.View implements definition.ListView {
public _prepareItem(item: view.View, index: number) {
if (item) {
item.bindingContext = this._getDataItem(index);
item._inheritProperties(this);
}
}
@@ -145,4 +146,8 @@ export class ListView extends view.View implements definition.ListView {
private _onItemsChanged(args: observable.EventData) {
this.refresh();
}
public _propagateInheritableProperties(view: view.View) {
// do not get binding context from parent when adding items, since the binding context of the items will be different.
}
}