0
votes

How can I refer the controls inside the ViewCell of a ListView:

    <ListView x:Name="classesListView"
              ItemsSource="{Binding List}"
              HasUnevenRows="True" 
              HeightRequest="200" 
              ItemSelected="ListView_OnSelection">
      <ListView.ItemTemplate>
        <DataTemplate>
          <ViewCell Height="50">
            <StackLayout Orientation="Horizontal">
              <Switch x:Name="chooseItem" VerticalOptions="Center"/>
              <Label Text="{Binding ClassName}" VerticalOptions="Center"/>
            </StackLayout>
          </ViewCell>
        </DataTemplate>
      </ListView.ItemTemplate>
    </ListView>

How can I refer to the Switch in the code behind(in the ListView_OnSelection method)

Thanks

1
It's better to use binding. Tell me, please, what do you want to handle in Switch?Yehor Hromadskyi
I need to add the Label text to an array if the switch is toggledMireille

1 Answers

0
votes

You could add new property to model and the use binding to see if Switch IsToggled:

<Switch x:Name="chooseItem" 
        VerticalOptions="Center" 
        IsToggled="{Binding IsSelectedForBeingAddedToArray, Mode=TwoWay}" />