我对ObservableCollection有一些问题,在我的列表中添加了值,但它们没有显示在我的列表视图中

时间:2016-07-04 13:58:36

标签: c# xamarin.forms

这是我到目前为止编写的代码,ObservableCollection列表中填充了字符串值,但列表视图不会显示文本。有什么目标缺失或做错了吗?如果有人能给我一些回复,我会很高兴!

public class interactiveListViewCode : ContentPage
{
    public static ObservableCollection<string> items { get; set; }


    public interactiveListViewCode()
    {

        items = new ObservableCollection<string>() { };
        //List<string> items = new List<string>();
        ListView lstView = new ListView();
        lstView.IsPullToRefreshEnabled = true;
        //lstView.Refreshing += OnRefresh;
        lstView.ItemSelected += OnSelection;
        lstView.ItemTapped += OnTap;
        lstView.ItemsSource = items;
        var temp = new DataTemplate(typeof(textViewCell));
        lstView.ItemTemplate = temp;
        Content = lstView;
    }

    internal void insertComanyName(String[] companyName, String[] idForCompany)
    {

        for (int i = 0; i < companyName.Length; i++)
        {
            string temp;
            temp = companyName[i];
            items.Add(temp);
            Debug.WriteLine("this is in the items List " + items[i]);
        }

    }

这也是&#34; textViewCell&#34;类:

public class textViewCell:ViewCell     {         public textViewCell()         {             StackLayout layout = new StackLayout();             layout.Padding = new Thickness(15,0);             Label label = new Label();

        label.SetBinding(Label.TextProperty, ".");
        layout.Children.Add(label);

        var moreAction = new MenuItem { Text = "More" };
        moreAction.SetBinding(MenuItem.CommandParameterProperty, new Binding("."));
        moreAction.Clicked += OnMore;

        var deleteAction = new MenuItem { Text = "Delete", IsDestructive = true }; // red background
        deleteAction.SetBinding(MenuItem.CommandParameterProperty, new Binding("."));
        deleteAction.Clicked += OnDelete;

        this.ContextActions.Add(moreAction);
        this.ContextActions.Add(deleteAction);
        View = layout;
    }

0 个答案:

没有答案