Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...