ListView.GroupShortNameBinding 属性

定义

获取或设置要在分组跳转列表中显示的名称的绑定。

public Xamarin.Forms.BindingBase GroupShortNameBinding { get; set; }
member this.GroupShortNameBinding : 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" }
        }
  };
}

注解

在 中 ListView对项进行分组时,让跳转列表跳转到列表中的特定部分通常很有用。 例如,在按字母顺序分组的列表中,跳转列表将是每个组的字母。 此绑定针对 IEnumerable 每个组的 应用,以选择要在跳转列表中显示的短名称。

注意:在 Android 上,没有显示的跳转列表。

适用于