如何引用ListView
的{{1}}内的控件:
<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>
如何在后面的代码中引用Switch
(在ListView_OnSelection
方法中)
由于
答案 0 :(得分:0)
您可以向模型添加新属性,并使用绑定来查看Switch
IsToggled
:
<Switch x:Name="chooseItem"
VerticalOptions="Center"
IsToggled="{Binding IsSelectedForBeingAddedToArray, Mode=TwoWay}" />