xaml - 如何使用xamarin表单在 ListView 中添加复选框

标签 xaml checkbox xamarin.forms

我想使用xaml在 ListView 中创建一个复选框,选择多个复选框后单击按钮获取所有选定的值。我的代码是:

<ContentPage.Content>
    <ListView  x:Name="ProductsListView">
        <ListView.ItemTemplate>
            <DataTemplate>
                <ViewCell>
                    <ViewCell.View>
                        <StackLayout Spacing="0">
                            <Label Text="{Binding retail_modified_item_id}" 
                               TextColor="Blue" FontSize="13" />
                            <Label Text="{Binding name, StringFormat='Name : 
                               {0:N}'}" TextColor="black" FontSize="10"  />
                            <Label Text="{Binding retail_price, 
                               StringFormat='Price : {0:N}'}" 
                               TextColor="black" FontSize="10" />
                        </StackLayout>
                    </ViewCell.View>
                </ViewCell>                            
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>
</ContentPage.Content>

我的输出是; output without checkbox

我尝试了 https://www.ignatiuz.com/blog/xamarin/button-check-box-with-list-item-in-xamarin-forms-listview/ 中的一些示例代码

但我收到输入:未找到复选框

我是 xamarin 新手,请提供一些示例代码或链接来执行此操作

最佳答案

您可以使用Plugin.InputKit来自 Nuget。

Usage

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:xxx"
             xmlns:input="clr-namespace:Plugin.InputKit.Shared.Controls;assembly=Plugin.InputKit"
             x:Class="xxx.MainPage">


<ContentPage.Content>
 <ListView  x:Name="ProductsListView">
    <ListView.ItemTemplate>
        <DataTemplate>
            <ViewCell>
                <ViewCell.View>
                    <StackLayout Spacing="0">
                        <Label Text="{Binding retail_modified_item_id}" 
                           TextColor="Blue" FontSize="13" />
                        <Label Text="{Binding name, StringFormat='Name : 
                           {0:N}'}" TextColor="black" FontSize="10"  />
                        <Label Text="{Binding retail_price, 
                           StringFormat='Price : {0:N}'}" 
                           TextColor="black" FontSize="10" />
                        <input:CheckBox Text="xxx" Type="Check"/>  
                    </StackLayout>
                </ViewCell.View>
            </ViewCell>                            
        </DataTemplate>
    </ListView.ItemTemplate>
 </ListView>
</ContentPage.Content>        

</ContentPage>

关于xaml - 如何使用xamarin表单在 ListView 中添加复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55350643/

相关文章:

c# - 无法从 UWP 应用连接到本地主机上托管的 Web 服务

c# - 绑定(bind)ContentControl内容以获取动态内容

api - 如何使用 Xamarin 在单元格 View 中显示数据

sqlite - Azure/Xamarin 移动应用程序在 SyncContext.InitializeAsync 处挂起

c# - xamarin 形式 xaml OnPlatform 不处理绑定(bind)

checkbox - 如何在使用 powershell 安装 msi 期间设置复选框?

c# - 访问元素组件 silverlight

c# - 如何在 C# 中使用 XAML 中定义的画笔资源

javascript - 通过 Jquery 更改按钮值

android - 如何使用自定义适配器和 ListView 获取复选框值