Skip to content

Commit d0170a4

Browse files
author
Jonathan Peppers
committed
Fix for BindingContext in ListView Header or Footer
1 parent 4fa3c8c commit d0170a4

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

Xamarin.Forms.Core/ListView.cs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,5 +536,36 @@ static bool ValidateHeaderFooterTemplate(BindableObject bindable, object value)
536536
var template = (DataTemplate)value;
537537
return template.CreateContent() is View;
538538
}
539-
}
539+
540+
protected override void OnBindingContextChanged()
541+
{
542+
base.OnBindingContextChanged();
543+
544+
//NOTE: BindingContext was not passing through ListView to its Header or Footer
545+
546+
var gotBindingContext = false;
547+
object bc = null;
548+
549+
var header = Header as Element;
550+
if (header != null)
551+
{
552+
bc = BindingContext;
553+
gotBindingContext = true;
554+
555+
SetChildInheritedBindingContext(header, bc);
556+
}
557+
558+
var footer = Footer as Element;
559+
if (footer != null)
560+
{
561+
if (!gotBindingContext)
562+
{
563+
bc = BindingContext;
564+
gotBindingContext = true;
565+
}
566+
567+
SetChildInheritedBindingContext(footer, bc);
568+
}
569+
}
570+
}
540571
}

0 commit comments

Comments
 (0)