Xamarin Listview数据没有出现?

时间:2015-03-27 15:43:19

标签: c# listview data-binding xamarin xamarin.forms

我决定在所有可以在ListView上显示多个数据字段的平台上需要自定义ListView。所以我决定查看https://github.com/xamarin/xamarin-forms-samples/tree/master/WorkingWithListviewNative中的代码并在我的模块中修改它。但是我的ListView永远不会显示任何值/视图,我不知道为什么。

HorsePage.xaml:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         x:Class="Begijnhoeve.Pages.HorsesPage"
         Title="Horse Overview">
</ContentPage>

HorsePage.xaml.cs:

var nativeListViewHorse = new NativeListViewHorse(); // CUSTOM RENDERER using a native control
        nativeListViewHorse.VerticalOptions = LayoutOptions.FillAndExpand;
        nativeListViewHorse.Items = DAHorse.DataAccess.DAHorse.GetList();
        Content = new StackLayout
        {
            Padding = new Thickness(0, Device.OnPlatform(20, 0, 0), 0, 0),
            Children = {
                new Label {
                    XAlign = TextAlignment.Center,
                    Text = Device.OnPlatform("Custom UITableView+UICell","Custom ListView+Cell","Custom renderer todo")
                },
                nativeListViewHorse
            }
        };

DAHorse.cs(数据访问层):

namespace DAHorse.DataAccess
{
  class DAHorse
  {
    private static object locker = new object();
    private static SQLiteConnection db = DependencyService.Get<ISQLite_PCL>().GetConnection();
    public static List<Horse> GetList()
    {
        var l = new List<Horse>();

        l.Add(new Horse("HorseA", "1999"));
        l.Add(new Horse("HorseB", "2000"));
        l.Add(new Horse("HorseC", "2000"));
        Debug.WriteLine("YAPYAPYAPYAP");
        return l;
    }
  }
}

NativeListViewHorse.cs(自定义列表视图):

public class NativeListViewHorse : View
{
    public static readonly BindableProperty ItemsProperty =
        BindableProperty.Create("Items", typeof(IEnumerable<Horse>), typeof(NativeListViewHorse), new List<Horse>());

    public IEnumerable<Horse> Items
    {
        get { return (IEnumerable<Horse>)GetValue(ItemsProperty); }
        set { SetValue(ItemsProperty, value); }
    }

    public event EventHandler<SelectedItemChangedEventArgs> ItemSelected;

    public void NotifyItemSelected(object item)
    {

        if (ItemSelected != null)
            ItemSelected(this, new SelectedItemChangedEventArgs(item));
    }

    public NativeListViewHorse()
    {
    }
}

当我调试填充Content的行时,我将获得以下数据: 为什么在变量中看到数据时没有出现任何内容?我做错了什么或者?

亲切的问候, Yenthe

0 个答案:

没有答案