Xamarin.Forms Guides | Samples

Xamarin.Forms.ListView.GroupDisplayBinding Property

Gets or sets the binding to use for display the group header.

Syntax

public BindingBase GroupDisplayBinding { get; set; }

Value

The BindingBase instance to apply to grouped lists, or ..

Remarks

This binding can be used to simply set a the text of the group headers without defining a full template and uses the default visuals of the platform to display it. The binding is applied to the IEnumerable of the group.

This property is mutually exclusive with ListView.GroupHeaderTemplate property. Setting it will set ListView.GroupHeaderTemplate to null.

Example

This example shows an alphabetized list of people, grouped by first initial with the display binding set.

C# Example

    class Person
    {
        public string FullName
        {
            get;
            set;
        }

        public string Address
        {
            get;
            set;
        }
    }

C# Example

    class Group : ObservableCollection<Person>
    {
        public Group (string firstInitial)
        {
            FirstInitial = firstInitial;
        }

        public string FirstInitial
        {
            get;
            private set;
        }
    }

C# Example

    ListView CreateListView()
    {
        var listView = new ListView {
            IsGroupingEnabled = true,
            GroupDisplayBinding = new Binding ("FirstInitial"),
            GroupShortNameBinding = new Binding ("FirstInitial")
        };

        var template = new DataTemplate (typeof (TextCell));
        template.SetBinding (TextCell.TextProperty, "FullName");
        template.SetBinding (TextCell.DetailProperty, "Address");

        itemsView.ItemTemplate = template;
        itemsView.ItemsSource = new[] {
            new Group ("C") {
                new Person { FullName = "Caprice Nave" }
            },

            new Group ("J") {
                new Person { FullName = "James Smith", Address = "404 Nowhere Street" },
                new Person { FullName = "John Doe", Address = "404 Nowhere Ave" }
            }
        };
    }

Requirements

Namespace: Xamarin.Forms
Assembly: Xamarin.Forms.Core (in Xamarin.Forms.Core.dll)
Assembly Versions: 1.0.0.0, 1.1.0.0, 1.2.0.0, 1.3.0.0, 1.3.5.0, 1.4.0.0, 1.5.0.0, 2.0.0.0