如何获得选定项的数量CollectionView Xamarin?

问题描述 投票:0回答:1

我有一个ContentView,我想在其中获取所选项目的数量。另外,如果选择了两个以上的项目,如何禁用选择呢?

public class ListViewEx1
{
    public string Text { get; set; }
    public int Num { get; set; }
}

var collectionView1_one = new CollectionView(){ 
    SelectionMode = SelectionMode.Multiple,
    ItemsSource = new List<ListViewEx1>() 
    {
        new ListViewEx1{ Text = "1) Onetext", Num = 1 },
        new ListViewEx1{ Text = "2) text", Num = 2 },
        new ListViewEx1 { Text = "3) ggfggf", Num = 3 },
        new ListViewEx1{ Text = "4) affff", Num = 4 },
        new ListViewEx1{ Text = "5) zzzzzzzz", Num = 5 },
    },
    ItemTemplate = new DataTemplate(() => 
    {
        Label titleLabel = new Label { FontSize = 18 }; 
        titleLabel.SetBinding(Label.TextProperty, "Text");

        return new StackLayout 
        {
                Orientation = StackOrientation.Vertical,
                Children = {
                    titleLabel
                }
        };
    })
};
StackLayoutMap.Children.Add(collectionView1_one);
c# xamarin xamarin.forms xamarin.android
1个回答
0
投票

我想获得其中选定项目的数量

var count = collectionView1_one.SelectedItems.Count();
© www.soinside.com 2019 - 2024. All rights reserved.