我正在尝试在 Xamarin Forms 中实现 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;
}
有更好的方法吗?
我想要这样的东西,没有字母表和搜索菜单:
最佳答案
看看这个 https://github.com/ricardoromo/Listview-Multiselect ,我做了这个示例来模拟miltiselect listview。
关于c# - Xamarin Forms ListView 复选标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31687242/