ListView.GroupDisplayBinding 属性

定义

获取或设置要用于显示组标头的绑定。

public Xamarin.Forms.BindingBase GroupDisplayBinding { get; set; }
member this.GroupDisplayBinding : Xamarin.Forms.BindingBase with get, set

属性值

BindingBase要应用于分组列表的 实例,或 null

示例

此示例显示了按字母顺序排列的人员列表,该列表按第一个首字母和显示绑定集进行分组。

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

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

    public string FirstInitial
    {
        get;
        private set;
    }
}
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" }
        }
    };
}

注解

此绑定可用于仅设置组标头的文本,而无需定义完整模板,并使用平台的默认视觉对象来显示它。 绑定应用于 IEnumerable 组的 。

此属性与 GroupHeaderTemplate 属性互斥。 将其设置为 GroupHeaderTemplatenull

适用于