0
爲我的應用程序我想要一個非常簡單的listview,所以在我的VS中,我右鍵單擊 - >添加新項目 - >列表視圖頁面。我沒在的.xaml或的.csXamarin Forms ListView不顯示文本
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
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;
}
列表僅顯示細胞改變什麼,沒有文字
我試着改變綁定,添加textColor等,但無論如何,單元格保持爲空
哇,非常感謝,我沒有想到這一點。我很困惑,因爲我假設模板可以開箱即用。 – wasido