Xamarin.forms Xamarin ListView未与DateTime绑定一起出现

Xamarin.forms Xamarin ListView未与DateTime绑定一起出现,xamarin.forms,Xamarin.forms,在这方面有很多类似的问题,但我还没有找到一个适合我的解决方案。我有一个listview,当绑定到类成员的列表时,它根本不会出现。我有很多工作绑定,我只是不知道我在这一个做错了什么。我的listview XAML: <ListView ItemsSource="{Binding DisplayTimecard.Days}" SelectedItem="{Binding SelectedItem}"> <ListView.

在这方面有很多类似的问题,但我还没有找到一个适合我的解决方案。我有一个listview,当绑定到类成员的列表时,它根本不会出现。我有很多工作绑定,我只是不知道我在这一个做错了什么。我的listview XAML:

<ListView ItemsSource="{Binding DisplayTimecard.Days}"
                  SelectedItem="{Binding SelectedItem}">
            <ListView.Behaviors>
            <ioc:EventToCommandBehavior EventName="ItemTapped" 
                                      Command="{Binding ClickedDateCommand}"
                                      EventArgsConverter="{StaticResource ItemTappedEventArgsConverter}" />
            </ListView.Behaviors>
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <StackLayout Orientation="Vertical">
                            <StackLayout Orientation="Horizontal">
                                <Label Text="{Binding Path=Date, StringFormat=dd-MM-yyyy}"/>
                            </StackLayout>
                        </StackLayout>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
调用该集合的方法是列表中的日期:

 public void SetDisplayDates()
        {
            for (var date = SelectedPayPeriod.StartDate; date <= SelectedPayPeriod.EndDate; date = date.AddDays(1))
            {
                DisplayTimecard.Days.Add(date);//List<DateTime> named in ListView's ItemsSource
            }
            RaisePropertyChanged("DisplayTimecard.Days");
        }

我已经搜索了许多现有的问题,但我没有找到一个适合我的解决方案。如果有人能解释一下这个问题,或者给我指出一个存在的问题,我会非常感激。

好吧,我终于明白我做错了什么,或者至少知道什么现在起作用了。从MS文档:

If you want the ListView to automatically update as items are added, removed and changed in the underlying list, you'll need to use an ObservableCollection.
因此,我将我的列表更改为可观察的集合:

 public ObservableCollection<DateTime> Dates
        {
            get { return _dates; }
            set { SetProperty(ref _dates, value); }
        }
公共可观测收集日期
{
获取{返回日期;}
set{SetProperty(ref_dates,value);}
}
我还更改了Xaml绑定语法:

<ListView ItemsSource="{Binding Dates}"
                  SelectedItem="{Binding SelectedItem}">
            <ListView.Behaviors>
            <ioc:EventToCommandBehavior EventName="ItemTapped" 
                                      Command="{Binding ClickedDateCommand}"
                                      EventArgsConverter="{StaticResource ItemTappedEventArgsConverter}" />
            </ListView.Behaviors>
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <StackLayout Orientation="Vertical">
                            <StackLayout Orientation="Horizontal">
                                <Label Text="{Binding Date, StringFormat='{0:dd-MM-yyyy}'}"/>
                            </StackLayout>
                        </StackLayout>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>


我希望有一天,我的努力可能会帮助别人。

好吧,我终于明白我做错了什么,或者至少知道什么现在起作用了。从MS文档:

If you want the ListView to automatically update as items are added, removed and changed in the underlying list, you'll need to use an ObservableCollection.
因此,我将我的列表更改为可观察的集合:

 public ObservableCollection<DateTime> Dates
        {
            get { return _dates; }
            set { SetProperty(ref _dates, value); }
        }
公共可观测收集日期
{
获取{返回日期;}
set{SetProperty(ref_dates,value);}
}
我还更改了Xaml绑定语法:

<ListView ItemsSource="{Binding Dates}"
                  SelectedItem="{Binding SelectedItem}">
            <ListView.Behaviors>
            <ioc:EventToCommandBehavior EventName="ItemTapped" 
                                      Command="{Binding ClickedDateCommand}"
                                      EventArgsConverter="{StaticResource ItemTappedEventArgsConverter}" />
            </ListView.Behaviors>
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <StackLayout Orientation="Vertical">
                            <StackLayout Orientation="Horizontal">
                                <Label Text="{Binding Date, StringFormat='{0:dd-MM-yyyy}'}"/>
                            </StackLayout>
                        </StackLayout>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>


我希望有一天我的奋斗会帮助别人。

你可以标记它,它将帮助更多有同样问题的人:)。你可以标记它,它将帮助更多有同样问题的人:)。