C# 当listview为“时,如何通过单击获取整个类”;instagram设计“;?

C# 当listview为“时,如何通过单击获取整个类”;instagram设计“;?,c#,xamarin,xamarin.forms,C#,Xamarin,Xamarin.forms,所以我想要实现的是,当你点击一个图像时,我想要该类的全部数据。因此,如果看看当前的示例,我有一个图像+一个名称(我打算在此基础上继续) 我还为每个项目分配了一个rowID,并将其绑定到其classid,以便以某种方式使用它来检索整个数据类 我的XAML: <ListView x:Name="imagesListview"> <ListView.ItemTemplate> <DataTemplate>

所以我想要实现的是,当你点击一个图像时,我想要该类的全部数据。因此,如果看看当前的示例,我有一个图像+一个名称(我打算在此基础上继续)

我还为每个项目分配了一个rowID,并将其绑定到其classid,以便以某种方式使用它来检索整个数据类

我的XAML:

<ListView x:Name="imagesListview">
        <ListView.ItemTemplate>
            <DataTemplate>
                <ViewCell>
                    <ViewCell.View>
                        <AbsoluteLayout>

                            <Button Image="{Binding theimage}" 
                            AbsoluteLayout.LayoutBounds="0.0, 0.0, 0.333, 1.0" Text = "{Binding thename}" 
                            AbsoluteLayout.LayoutFlags="All" ClassId = "{Binding rowid}" Clicked = "OnImageTapped"/>

                           <Button Image="{Binding theimage2}" AbsoluteLayout.LayoutBounds="0.5, 0.0, 0.333, 1.0" Text = "{Binding thename2}"  
                            AbsoluteLayout.LayoutFlags="All" ClassId = "{Binding rowid}"  Clicked = "OnImageTapped"/>

                            <Button Image="{Binding theimage3}" 
                            AbsoluteLayout.LayoutBounds="1.0, 0.0, 0.333, 1.0" AbsoluteLayout.LayoutFlags="All" Text = "{Binding thename3}"  ClassId = "{Binding rowid}" Clicked = "OnImageTapped"/>

                        </AbsoluteLayout>
                    </ViewCell.View>
                </ViewCell>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>
如何从数据库加载图像

new List<info> imagesList = new List<info> ();

async void loadPhotos ()
{

    int ndx = 0;
    info Info = null;
    var getInfo = await phpApi.getPhotos ();

    imagesListview.ItemsSource = null;
    imagesList = new List<info> ();

    foreach (var items in getInfo["results"]) {

        if (ndx == 0) {
            Info = new info();
            Info.theimage = items ["Photo"].ToString();
            Info.rowid = "1";
            Info.thename = items ["Name"].ToString();
            ndx++;
        } else

            if (ndx == 1) {
                Info.theimage2 = items ["Photo"].ToString();
                Info.rowid = "2";
                Info.thename2 = items ["Name"].ToString();
                ndx++;
            } else

                if (ndx == 2) {
                    Info.theimage3 = items ["Photo"].ToString();
                    Info.rowid = "3";
                    Info.thename3 = items ["Name"].ToString();
                    imagesList.Add(Info);
                    Info = null;
                    ndx = 0;
                }
    }

    if (Info != null) {
        imagesList.Add(Info);
    }

    imagesListview.ItemsSource = imagesList;

}
在XAML中,绑定时使用“.”路径绑定整个对象

CommandParameter = "{Binding .}"
然后在事件处理程序中

async void OnImageTapped(object sender, EventArgs eventArgs) { 

   var button = (Button)sender;
   var item = (info)button.CommandParameter;
}
CommandParameter = "{Binding .}"
async void OnImageTapped(object sender, EventArgs eventArgs) { 

   var button = (Button)sender;
   var item = (info)button.CommandParameter;
}