Xamarin.forms Xamarin表单-如何使用ListVIew

Xamarin.forms Xamarin表单-如何使用ListVIew,xamarin.forms,Xamarin.forms,我正在尝试用我创建的customcell填充listview。我知道如何使用tableview,但不知道如何使用listview。请有人给我解释一下,谢谢请原谅这段非常粗糙的代码,但它只是解释ListView和数据绑定背后的概念 在下面的示例中,我创建了一个listview,指定了一个自定义viewCell,并将该viewCell绑定到一个模型。模型数据由从服务器检索的XML数据填充,为简单起见,发出了代码。如果需要具有硬编码数据的listview,则可以执行更简单的实现 我建议阅读并研究MVV

我正在尝试用我创建的customcell填充listview。我知道如何使用tableview,但不知道如何使用listview。请有人给我解释一下,谢谢

请原谅这段非常粗糙的代码,但它只是解释ListView和数据绑定背后的概念

在下面的示例中,我创建了一个listview,指定了一个自定义viewCell,并将该viewCell绑定到一个模型。模型数据由从服务器检索的XML数据填充,为简单起见,发出了代码。如果需要具有硬编码数据的listview,则可以执行更简单的实现

我建议阅读并研究MVVM原理

此外,我发现最好的示例代码是James Montemagno编写的一个启发性应用程序

自定义视图单元格: 视图模型:
可能重复的问题请不要多次问同一个问题。
public TestPage()
  {

     private ListView listView; // Create a private property with the Type of Listview named listview
     listView = new ListView(); //Instantiate the listview 
     var viewTemplate = new DataTemplate(typeof(CustomViewCell)); //Create a variable for the custom data template
     listView.ItemTemplate = viewTemplate; // set the data template to the variable created above 

 this.Content = new StackLayout()
  {
    Children = {
    listView
  }
};

}
public class CustomViewCell : ViewCell
{
    public CustomViewCell()
    {

        Label Test = new Label()
        {
            Font = Font.BoldSystemFontOfSize(17),
            TextColor = Helpers.Color.AppGreen.ToFormsColor(),
            BackgroundColor = Color.White
        };

        var image = new Image();
        image.Source = ImageSource.FromFile("testing.png");

        Label Test2 = new Label();

        tour_Desc.SetBinding(Label.TextProperty, "Test");
        round_Desc.SetBinding(Label.TextProperty, "Test2");

        var grid = new Grid
        {
            VerticalOptions = LayoutOptions.FillAndExpand,

            RowDefinitions = 
            {
                new RowDefinition {Height = GridLength.Auto },
                new RowDefinition {Height = GridLength.Auto },
                new RowDefinition {Height = 1}
            },
            ColumnDefinitions = 
            {
                new ColumnDefinition {Width = GridLength.Auto},
                new ColumnDefinition {Width = new GridLength(1, GridUnitType.Star)},
                new ColumnDefinition {Width = 80 }
            }
            ,BackgroundColor = Color.White,
        };

        grid.Children.Add(image, 0, 0);
        Grid.SetRowSpan(image, 2);

        grid.Children.Add(tour_Desc, 1, 0);
        Grid.SetColumnSpan(tour_Desc, 2);

        grid.Children.Add(Test, 1, 1);
        grid.Children.Add(Test2, 1, 2);

        this.View = grid;
    }

}
public partial class GamesResult
{
    public string Test { get; set; }

    public string Test1 { get; set; }
}