I have a ListView with some Labels, a Toggle and an Entry. There are several records in the ListView. When I touch a Toggle, the OnToggle brings me to the OnToggle method. What I need is to know is what Item that Toggle is part of. The same goes for the Entry.
If I just tap on the Toggle (without tapping on the cell), then in the OnToggle I get a null for MyListView.SelectedItem.
If I tap on the cell and then tap the Toggle, then in the OnToggle I do get a value for MyListView.SelectedItem. However, if I then tap on another Toggle (without tapping on the new cell) the SelectedItem does not change and that is not good.
Any insight is greatly appreciated. Now, here is the XAML:
<ListView x:Name="MyListView" SeparatorVisibility="None" BackgroundColor="Black" HasUnevenRows="True" >
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<StackLayout Orientation="Vertical" Margin="0,0,0,10" BackgroundColor="White">
<StackLayout Orientation="Horizontal">
<Label Text="{Binding trq.tech_reportID}" FontSize="18" BackgroundColor="White" TextColor="Black"
MinimumWidthRequest="40"/>
<Label Text="{Binding trq.questions}" FontSize="18" BackgroundColor="White" TextColor="Black"/>
</StackLayout>
<StackLayout Orientation="Horizontal">
<Label Text="No" TextColor="Black" IsVisible="{Binding ShowToggle}" FontSize="18" />
<Switch x:Name="AnswerToggle"
IsEnabled="True" IsToggled="{Binding AnswerToggle}"
IsVisible="{Binding ShowToggle}"
BackgroundColor="Black" Toggled="Answer_Toggled"/>
<Label Text="Yes" TextColor="Black" IsVisible="{Binding ShowToggle}" FontSize="18" />
</StackLayout>
<StackLayout Orientation="Vertical" Margin="0,0,0,0" BackgroundColor="Black" >
<Entry x:Name="Explanation" Text="{Binding tr.explanation , Mode=TwoWay}"
FontSize="18" BackgroundColor="White"
TextColor="Black" Placeholder="Explanation" Margin="0,3,0,0"
MinimumWidthRequest="200" TextChanged="Entry_TextChanged" />
</StackLayout>
</StackLayout>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>