F
F
Frendy2020-02-25 21:31:10
C++ / C#
Frendy, 2020-02-25 21:31:10

How to disable selectability if more than two CollectionView Xamarin items are selected?

I have a ContentView and I want to get the number of selected items in it.
Also, how do I disable the ability to select if more than two items are selected?

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);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
#
#, 2020-02-25
@Frendy

https://docs.microsoft.com/ru-ru/xamarin/xamarin-f...
https://docs.microsoft.com/ru-ru/dotnet/api/xamari...
something tells me that collectionView1_one.SelectedItems.Count;
moreover, the banal IntelliSense of the visual studio, when entering a point, and viewing the options, it should show a
sin to ask such questions
ps and you can also press F1 on the data type. in your case CollectionView. and get links that at the beginning of the response

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question