【问题标题】:Xamarin.forms ListView click to next pageXamarin.forms ListView 点击下一页
【发布时间】:2016-07-13 11:20:17
【问题描述】:

单击特定列表项时,我无法将值(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));
    }

【问题讨论】:

    标签: c# xaml xamarin.forms


    【解决方案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));
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-07-06
      • 2021-05-09
      • 2014-11-11
      • 2018-12-08
      • 1970-01-01
      • 2016-06-05
      • 1970-01-01
      • 2021-07-27
      相关资源
      最近更新 更多