小编Ele*_*ina的帖子

为什么我的列表视图似乎为空?

我是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)

调试应用程序时,列表中没有任何内容,如果有人可以告诉我我做错了什么,我将不胜感激!

c# xaml xamarin xamarin.forms

5
推荐指数
1
解决办法
2609
查看次数

标签 统计

c# ×1

xamarin ×1

xamarin.forms ×1

xaml ×1