簡體   English   中英

Xamarin.forms ListView單擊到下一頁

[英]Xamarin.forms ListView click to next page

當我單擊特定列表項時,無法將value(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));
    }

您沒有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));
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM