点击特定列表项后,我无法将值(id)传递给下一页。
我的Xaml文件
<ListView x:Name="Clublistview" HasUnevenRows="true" ItemSelected="OnItemSelected">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell Height="50">
<StackLayout BackgroundColor="White"
Orientation="Vertical">
<StackLayout Orientation="Horizontal">
<Image Source="{Binding Logo}" IsVisible="true" WidthRequest="50" HeightRequest="50"/>
</StackLayout>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
我的.CS文件
async void OnItemSelected(object sender, SelectedItemChangedEventArgs e)
{
ListView btn = (ListView)sender;
int clubid = (int)btn.CommandParameter;
await Navigation.PushAsync(new DetailedClub(clubid));
}
答案 0 :(得分:1)
您没有将CommandParameter绑定到任何内容。一种更简单的方法是
async void OnItemSelected(object sender, SelectedItemChangedEventArgs e)
{
ListView lv = (ListView)sender;
// this assumes your List is bound to a List<Club>
Club club = (Club) lv.SelectedItem;
// assuiming Club has an Id property
await Navigation.PushAsync(new DetailedClub(club.Id));
}