CollectionView 不显示元素,直到我在调试模式下使用 xamarin 棱镜重新保存 xaml 页面

问题描述

第一次面对这个,不知道是不是来自prism,但是好像collection view不接受第一次的数据。

Initial debug mode

After re-save xaml file during debug

Xmal 代码一个普通的集合视图

查看型号代码

public class FacilitiesViewviewmodel : viewmodelBase,INavigationAware
    {
        other variables deFinitions

        private readonly INavigationService _navigationService;
        public ObservableCollection<Court> CourtsItemsBySport { get; set; }

        public FacilitiesViewviewmodel(INavigationService navigationService) :
            base(navigationService)
        {
            _navigationService = navigationService;
            CourtsItemsBySport = new ObservableCollection<Court>();

        }

        private async void GetCourtItems(int sportID)
        {
            var data = await new CourtDataService().GetCourtsItemsBySportAsync(sportID);
            CourtsItemsBySport.Clear();

            foreach (var item in data)
            {
                CourtsItemsBySport.Add(item);
            }
            TotalCourtItems = CourtsItemsBySport.Count(); /* this variable is shown during initial debug,and CourtsItemsBySport is having values but not shown in collectionview */
        }
// this function is getting the passed parameter from another view model

#pragma warning disable CS0114 // Member hides inherited member; missing override keyword

        public void OnNavigatedTo(INavigationParameters parameters)

#pragma warning restore CS0114 // Member hides inherited member; missing override keyword

        {
            SelectedSport = parameters.GetValue<Sport>("SelectedSport");
            CourtsItemsBySport = new ObservableCollection<Court>();
            GetCourtItems(SelectedSport.SportID);

        }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)