Bug 33872 - ListView footer layout BindingContext not set
Summary: ListView footer layout BindingContext not set
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 1.4.4
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2015-09-10 23:58 UTC by Simon Taylor
Modified: 2016-04-13 19:17 UTC (History)
6 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Simon Taylor 2015-09-10 23:58:18 UTC
In the code below the Command and IsVisible bindings of "moreButton" do not work without explicitly setting the BindingContext of the list footer in OnBindingContextChanged. Tested on iOS.

    public class BankBranchListView : PopupFrame, IPopupView
        public Button CancelButton { get; protected set; }

        private Layout _FooterLayout;

        public BankBranchListView(Branding branding)
            : base(branding, false)
            var layout = new StackLayout
                Style = branding.Styles.PageLayoutStyle,
                BackgroundColor = branding.Colors.PrimaryBackground

            var header = new PageHeaderView(branding, AppResources.Description_BankBranchSelect);

            var moreButton = new Button
                Text = AppResources.ButtonLabel_More,
                HorizontalOptions = LayoutOptions.FillAndExpand
            moreButton.SetBinding<BankBranchSearchViewModel>(Button.CommandProperty, v => v.LoadMoreCommand);
            moreButton.SetBinding<BankBranchSearchViewModel>(Button.IsVisibleProperty, v => v.Model.BSBNumber,
                                                        BindingMode.Default, new IsNullOrEmptyConverter());

            this.CancelButton = new Button
                Text = AppResources.ButtonLabel_Cancel,
                HorizontalOptions = LayoutOptions.FillAndExpand

            this._FooterLayout = new StackLayout
                HorizontalOptions = LayoutOptions.FillAndExpand,
                Children = { moreButton, this.CancelButton }

            var list = new CommandableListView
                ItemTemplate = new DataTemplate(() => new PaddedDetailStringModelCell<BankBranchModel>(branding, false)),
                Footer = this._FooterLayout,
                HasUnevenRows = true
            list.SetBinding<BankBranchSearchViewModel>(CommandableListView.ItemSelectCommandProperty, v => v.SelectBranchCommand);
            list.SetBinding<BankBranchSearchViewModel>(ListView.ItemsSourceProperty, v => v.Collection);


            this.View = layout;

        protected override void OnBindingContextChanged()

            this._FooterLayout.BindingContext = this.BindingContext;
Comment 1 Paul DiPietro [MSFT] 2015-09-12 19:11:58 UTC
It seems there are external elements related to the sample you provided, here; if you could kindly create a reproduction project isolating this issue in question, it would be much appreciated in helping the team to investigate it.
Comment 2 Simon Taylor 2015-09-24 00:30:26 UTC
ListView needs an OnBindingContextChanged() implementation like below. The base OnBindingContextChanged() implementation only applies to elements in LogicalChildren, which the header and footer aren't.

        protected override void OnBindingContextChanged()

            var bindableHeader = this.Header as BindableObject;
            if (bindableHeader != null)
                BindableObject.SetInheritedBindingContext(bindableHeader, this.BindingContext);

            var bindableFooter = this.Footer as BindableObject;
            if (bindableFooter != null)
                BindableObject.SetInheritedBindingContext(bindableFooter, this.BindingContext);