【发布时间】:2018-03-18 04:19:51
【问题描述】:
我正在尝试在 Xamarin 表单中实现 ListView。我们可以检查或选择我们想要的项目的列表。我想要一次选择一个项目。
我的 xaml 文件:
ListView x:Name="listview" ItemSelected="OnItemSelected" >
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout HorizontalOptions="StartAndExpand" Orientation="Horizontal">
<StackLayout Padding="20,0,0,0" VerticalOptions="Center" Orientation="Vertical">
<Label Text="{Binding .}" YAlign="Center" FontSize="Medium" />
</StackLayout>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
我的 xaml.cs 文件:
public void OnItemSelected (object sender, SelectedItemChangedEventArgs e) {
if (e.SelectedItem == null) return;
// add the checkmark in the event because the item was clicked
// be able to check the item here
DisplayAlert("Tapped", e.SelectedItem + " row was tapped", "OK");
((ListView)sender).SelectedItem = null;
}
有更好的方法吗?
我想要这样的东西,没有字母和搜索菜单:
【问题讨论】:
标签: c# listview xamarin xamarin.ios