检查ListView内的每个CheckBox [英] Check every CheckBox inside ListView

查看:106
本文介绍了检查ListView内的每个CheckBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Xamarin的新手.我想在Xamarin中设置一个ListView,外加2个按钮以选中/取消选中ListView中的每个CheckBox,以在之后利用选中的复选框.您能告诉我如何通过foreach循环访问这些复选框吗?

I'm new to Xamarin. I want to setup a ListView in Xamarin plus 2 buttons to check/uncheck every CheckBox inside the ListView to utilize the checked ones afterwards. Could you please tell me how to access these Checkboxes with kind of a foreach loop?

<ListView x:Name="countryListView" HasUnevenRows="true" ItemTapped="Handle_ItemTapped">
        <ListView.ItemTemplate>
            <DataTemplate>
                <ViewCell>
                    <ViewCell.ContextActions>
                        <MenuItem Text="Bla" CommandParameter="{Binding .}" />
                        <MenuItem Text="Delete" IsDestructive="true" CommandParameter="{Binding .}" Clicked="deleteCountry" />
                    </ViewCell.ContextActions>
                    <StackLayout Orientation="Horizontal" Padding="5">
                        <controls:CircleImage HeightRequest="30" WidthRequest="30" Aspect="AspectFill" Source="{Binding imageURL}" VerticalOptions="Center" HorizontalOptions="Center" />
                        <!--<Image Source="{Binding imageURL}" />-->
                        <StackLayout HorizontalOptions="StartAndExpand">
                            <Label Text="{Binding name}" />
                            <Label Text="{Binding capital}" />
                        </StackLayout>
                        <CheckBox x:Name="checkbox" IsChecked="false" />
                    </StackLayout>
                </ViewCell>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>

谢谢, 托马斯

推荐答案

绑定复选框的IsChecked属性以在ViewModel中设置布尔值,并在OnClick事件中使其为真或假.不要忘记实现INotifyPropertyChanged来刷新您的UI.

Bind the IsChecked property of your checkbox to bool in your ViewModel and in OnClick event make it true or false. Don't forget to implement INotifyPropertyChanged to refresh your UI.

这篇关于检查ListView内的每个CheckBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆