c# - Xamarin Forms ListView 复选标记

标签 c# listview xamarin xamarin.ios

我正在尝试在 Xamarin Forms 中实现 ListView。我们可以检查或选择我们想要的项目的列表。我想要一次选择一个项目。

我的 xaml 文件:

ListView x:Name="listview" ItemSelected="OnItemSelected" >
        <ListView.ItemTemplate>
            <DataTemplate>
                <ViewCell>
                    <StackLayout HorizontalOptions="StartAndExpand" Orientation="Horizontal">
                        <StackLayout Padding="20,0,0,0"  VerticalOptions="Center"  Orientation="Vertical">
                            <Label Text="{Binding .}" YAlign="Center" FontSize="Medium"   />
                        </StackLayout>
                    </StackLayout>
                </ViewCell>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>

我的 xaml.cs 文件:

    public void OnItemSelected (object sender, SelectedItemChangedEventArgs e) {
        if (e.SelectedItem == null) return; 

        // add the checkmark in the event because the item was clicked
       // be able to check the item here

        DisplayAlert("Tapped", e.SelectedItem + " row was tapped", "OK");
        ((ListView)sender).SelectedItem = null;
    }

有更好的方法吗?

我想要这样的东西,没有字母表和搜索菜单:

enter image description here

最佳答案

看看这个 https://github.com/ricardoromo/Listview-Multiselect ,我做了这个示例来模拟miltiselect listview。

关于c# - Xamarin Forms ListView 复选标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31687242/

相关文章:

c# - 处理从 CSV 导入的引号

android listview更新/刷新数据而不关闭应用程序

android - Parse.com 在 Xamarin 中在 Android 上推送

c# - 如何验证表单以防止重复输入?

c# - 使桌面客户端无需更新即可使用较新的 EF 数据库迁移

wpf - 绑定(bind)到结构

android - 如何在 LinearLayoutManager 中重叠项目 - RecyclerView(如堆叠卡片)

android - 如何在 MPAndroidChart Xamarin 中舍入条形图的百分比?

Xamarin Forms Microcharts 生成 "OutOfMemoryError"

C# - 将 .txt 文件读入 TextBox