简体   繁体   English

Xamarin窗体ListView不显示文本

[英]Xamarin Forms ListView not displaying Text

for my app I want a very simple listview, so in my VS, I right click -> add new item -> List View Page. 对于我的应用程序,我想要一个非常简单的列表视图,因此在VS中,我右键单击->添加新项目->列表视图页。 I didn't change anything in the .xaml or .cs 我没有更改.xaml或.cs中的任何内容

ListView.xaml ListView.xaml

<ListView ItemsSource="{Binding Items}"
        ItemTapped="Handle_ItemTapped"
        CachingStrategy="RecycleElement">

  <!--Built in Cells-->
  <ListView.ItemTemplate>
    <DataTemplate>
      <TextCell />
    </DataTemplate>
  </ListView.ItemTemplate>
</ListView>

ListView.xaml.cs ListView.xaml.cs

public ObservableCollection<string> Items { get; set; }

    public FacilityListView()
    {
        InitializeComponent();

        Items = new ObservableCollection<string>
        {
            "Item 1",
            "Item 2",
            "Item 3",
            "Item 4",
            "Item 5"
        };

        BindingContext = this;
    }

    async void Handle_ItemTapped(object sender, SelectedItemChangedEventArgs e)
    {
        if (e.SelectedItem == null)
            return;

        await DisplayAlert("Item Tapped", "An item was tapped.", "OK");

        //Deselect Item
        ((ListView)sender).SelectedItem = null;
    }

The list shows only the cells, without text 该列表仅显示单元格,不显示文本

没有文本的列表视图单元格

I tried changing the binding, adding textColor etc. but no matter what, the cells remain empty 我尝试更改绑定,添加textColor等,但是无论如何,单元格保持为空

your template just contains an empty TextCell. 您的模板仅包含一个空的TextCell。 You have to use binding to tell it what to display 您必须使用绑定来告诉它显示什么

<ListView.ItemTemplate>
  <DataTemplate>
    <TextCell Text="{Binding .}" />
  </DataTemplate>
</ListView.ItemTemplate>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM