我是Xamarin Forms和XAML的新手,我想<ListView>与A预约约会。我的XAML如下所示:
<ListView x:Name="appointmentsView"
ItemsSource="{Binding appointmentList}"
Grid.Row="1"
AbsoluteLayout.LayoutBounds="0.50, 0.2, 1, 0.5"
AbsoluteLayout.LayoutFlags="All">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<Label TextColor="Black" Text="{Binding app1}"></Label>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Run Code Online (Sandbox Code Playgroud)
代码看起来像这样:
public partial class Home : ContentPage
{
public ObservableCollection<Appointment> appointmentList = new ObservableCollection<Appointment> ();
public Employee Tom { get; set; }
public Appointment app1 { get; set; }
public Home ()
{
InitializeComponent ();
Tom = new Employee("Tom", "Tommen");
app1 = new Appointment(new DateTime(), Tom);
appointmentList.Add(app1);
appointmentsView.ItemsSource = appointmentList;
}
Run Code Online (Sandbox Code Playgroud)
调试应用程序时,列表中没有任何内容,如果有人可以告诉我我做错了什么,我将不胜感激!