Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

How to get a selected item in a listview when one of the Template control is selected

VuyiswaMasekoVuyiswaMaseko USMember ✭✭✭

Good Day All

i have list view defined like this

   <ListView x:Name="lstmembers"   VerticalOptions="FillAndExpand"  SelectionMode="Single" ItemSelected="lstmembers_ItemSelected"
                    CachingStrategy="RecycleElement"  
                    HasUnevenRows="True"  BackgroundColor="White"
                    IsPullToRefreshEnabled="True"
                            Refreshing="lstmembers_Refreshing"
                    ItemTapped="lstmembers_ItemTapped"  
                    RowHeight="75"
                    SeparatorColor="Gray"
                    SeparatorVisibility="None">
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <ViewCell>
                                <StackLayout Orientation="Horizontal">

                                            <Label
                        FontSize="15" 
                        HorizontalOptions="Start"
                        Text="{Binding AGE}"
                        TextColor="Gray"
                        XAlign="Start" /> 

                              <Switch IsToggled="{Binding BLOCKED_STATUS}"  Toggled="blocked_status_Toggled" x:Name="blocked_status" />
                                        </StackLayout> 
                            </ViewCell>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>

Now inside the listview i have a Switch control. this shows nicely but when i select the switch item i want to be able to get the SelectedItem on that line in the listview. Now as you can see i have blocked_status_Toggled event which is fired every time a switched is turned on and off. if this were a button i would attach a field to a CommandParameter, but a switch control is kinda limited.

So my question is how can i find the selected item if someone selected the switch option

Thanks

Best Answer

Answers

  • VuyiswaMasekoVuyiswaMaseko USMember ✭✭✭

    Thanks , this works

Sign In or Register to comment.