Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
273 views
in Technique[技术] by (71.8m points)

c# - Check every CheckBox inside ListView

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?

Layout

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

Thanks, Thomas

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...