Xamarin 窗体模型刷新问题



嗨,Xamarin Developers,

在其中一个类中,我有一个列表视图,我正在从视图模型中获取数据。因此,当用户按下标题时,我正在扩展列表,并且正在更改展开变量的值。当我下次加载页面时,也会展开变量。值仍为 true,默认情况下,列表将展开。谁能告诉我如何在每次页面加载时重置视图模型?

我的模型类。

public class CourseCatalogModel : ObservableCollection<DashboardCard>, INotifyPropertyChanged
{
    private bool _expanded;
    public string Title { get; set; }
    private int _dataCount;
    public int DataCount
    {
        get { return _dataCount; }
        set
        {
            if (_dataCount != value)
            {
                _dataCount = value;
                OnPropertyChanged("StateIcon");
                OnPropertyChanged("TitleColor");
            }
        }
    }
    public string TitleColor
    {
        get
        {
            if (DataCount == 0)
            {
                return "#FFAEB2B5";
            }
            return "#FF00588A";
        }
    }

    public bool Expanded
    {
        get { return _expanded; }
        set
        {
            if (_expanded != value)
            {
                _expanded = value;
                OnPropertyChanged("Expanded");
                OnPropertyChanged("StateIcon");
            }
        }
    }

    public string StateIcon
    {
        get
        {
            if (DataCount == 0)
            {
                return "expand_empty";
            }
            return Expanded ? "expand_iCon.png" : "collapse_icon.png";
        }
    }
    public CourseCatalogModel(string title, bool expanded = true)
    {
        Title = title;
        Expanded = expanded;
    }
    public static ObservableCollection<CourseCatalogModel> CourseCatalogAll { private set; get; }
    public static ObservableCollection<CourseCatalogModel> CourseCatalogRequired { private set; get; }
    public static ObservableCollection<CourseCatalogModel> CourseCatalogNotRequired { private set; get; }
    static CourseCatalogModel()
    {
        // Course Awaiting Approvel...
        CourseCatalogModel awaitingApprovel = new CourseCatalogModel("Awaiting Approval", false);
        var awaitingCards = CourseCatalogModuleHelper.GetAwaitingApprovels();
        foreach (var dashboardCard in awaitingCards)
        {
            awaitingApprovel.Add(dashboardCard);
        }
        // Course Pending Courses...
        CourseCatalogModel pendingCourses = new CourseCatalogModel("Pending Courses", false);
        var pendingCourseCards = CourseCatalogModuleHelper.GetPendingCourses();
        foreach (var dashboardCard in pendingCourseCards)
        {
            pendingCourses.Add(dashboardCard);
        }
        // Course Completed Courses...
        CourseCatalogModel completedCourses = new CourseCatalogModel("Completed Courses", false);
        var completedCourseCards = CourseCatalogModuleHelper.GetCompletedCourses();
        foreach (var dashboardCard in completedCourseCards)
        {
            completedCourses.Add(dashboardCard);
        }
        ObservableCollection<CourseCatalogModel>
            CourseCatalogdata = new ObservableCollection<CourseCatalogModel>();
        CourseCatalogdata.Add(awaitingApprovel);
        CourseCatalogdata.Add(pendingCourses);
        CourseCatalogdata.Add(completedCourses);
        CourseCatalogAll = CourseCatalogdata;
        GetRequiredCourseCatalogCards();
        GetNotRequiredCourseCatalogCards();
    }
    private static void GetRequiredCourseCatalogCards()
    {
        // Course Awaiting Approvel...
        CourseCatalogModel awaitingApprovel = new CourseCatalogModel("Awaiting Approval", false);
        var awaitingCards = CourseCatalogModuleHelper.GetAwaitingApprovels(AppConstants.CourseFilterRequired);
        foreach (var dashboardCard in awaitingCards)
        {
            awaitingApprovel.Add(dashboardCard);
        }
        // Course Pending Courses...
        CourseCatalogModel pendingCourses = new CourseCatalogModel("Pending Courses", false);
        var pendingCourseCards = CourseCatalogModuleHelper.GetPendingCourses(AppConstants.CourseFilterRequired);
        foreach (var dashboardCard in pendingCourseCards)
        {
            pendingCourses.Add(dashboardCard);
        }
        // Course Completed Courses...
        CourseCatalogModel completedCourses = new CourseCatalogModel("Completed Courses", false);
        var completedCourseCards = CourseCatalogModuleHelper.GetCompletedCourses(AppConstants.CourseFilterRequired);
        foreach (var dashboardCard in completedCourseCards)
        {
            completedCourses.Add(dashboardCard);
        }
        ObservableCollection<CourseCatalogModel>
            CourseCatalogdata = new ObservableCollection<CourseCatalogModel>();
        CourseCatalogdata.Add(awaitingApprovel);
        CourseCatalogdata.Add(pendingCourses);
        CourseCatalogdata.Add(completedCourses);
        CourseCatalogRequired = CourseCatalogdata;
    }
    private static void GetNotRequiredCourseCatalogCards()
    {
        // Course Awaiting Approvel...
        CourseCatalogModel awaitingApprovel = new CourseCatalogModel("Awaiting Approval", false);
        var awaitingCards = CourseCatalogModuleHelper.GetAwaitingApprovels(AppConstants.CourseFilterNotRequired);
        foreach (var dashboardCard in awaitingCards)
        {
            awaitingApprovel.Add(dashboardCard);
        }
        // Course Pending Courses...
        CourseCatalogModel pendingCourses = new CourseCatalogModel("Pending Courses", false);
        var pendingCourseCards = CourseCatalogModuleHelper.GetPendingCourses(AppConstants.CourseFilterNotRequired);
        foreach (var dashboardCard in pendingCourseCards)
        {
            pendingCourses.Add(dashboardCard);
        }
        // Course Completed Courses...
        CourseCatalogModel completedCourses = new CourseCatalogModel("Completed Courses", false);
        var completedCourseCards = CourseCatalogModuleHelper.GetCompletedCourses(AppConstants.CourseFilterNotRequired);
        foreach (var dashboardCard in completedCourseCards)
        {
            completedCourses.Add(dashboardCard);
        }
        ObservableCollection<CourseCatalogModel>
            CourseCatalogdata = new ObservableCollection<CourseCatalogModel>();
        CourseCatalogdata.Add(awaitingApprovel);
        CourseCatalogdata.Add(pendingCourses);
        CourseCatalogdata.Add(completedCourses);
        CourseCatalogNotRequired = CourseCatalogdata;
    }
    public event PropertyChangedEventHandler PropertyChanged;
    protected virtual void OnPropertyChanged(string propertyName)
    {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }
}

在我的页面中,这就是我更改值的方式

 public partial class CourseCatalogBaseClass : ContentPage
{
    public ObservableCollection<CourseCatalogModel> _allGroups;
    ObservableCollection<CourseCatalogModel> _expandedGroups;
    List<DashboardCard> allListData;
    ObservableCollection<DashboardCard> searchListData;
    private string screenLabelString = string.Empty;
    public ObservableCollection<FilterPopupModel> courseFilterPopupModels = new ObservableCollection<FilterPopupModel>();
    public CourseCatalogBaseClass(bool isFromQualifications = false)
    {
        InitializeComponent();
        if (isFromQualifications)
        {
            screenLabel.Text = "My Qualifications";
            screenLabelString = screenLabel.Text;
        }
        allListData = App.DashboardResponse.TrainingContentCards;
        CourseCatalogSearchListView.IsVisible = false;
        _allGroups = CourseCatalogModel.CourseCatalogAll;
        UpdateCourseCatalagListContent();
        InitilizeFilters();
    }
    private void InitilizeFilters()
    {
        courseFilterPopupModels.Add(new FilterPopupModel()
            {Title = "All Classes", TitleColor = Color.FromHex("#00588A")});
        courseFilterPopupModels.Add(new FilterPopupModel()
            {Title = "Required", TitleColor = Color.FromHex("#686868")});
        courseFilterPopupModels.Add(new FilterPopupModel()
            {Title = "Not Required", TitleColor = Color.FromHex("#686868")});
        courseFilterPopupModels.Add(new FilterPopupModel() {Title = "Help", TitleColor = Color.FromHex("#686868")});
    }
    private void CourseListHeaderTapped(object sender, EventArgs args)
    {
        int selectedIndex = _expandedGroups.IndexOf(
            ((CourseCatalogModel) ((Button) sender).CommandParameter));
        _allGroups[selectedIndex].Expanded = !_allGroups[selectedIndex].Expanded;
        UpdateCourseCatalagListContent();
    }
    void Handle_Search_Bar_TextChanged(object sender, Xamarin.Forms.TextChangedEventArgs e)
    {
        var entry = (Entry) sender;
        searchListData = new ObservableCollection<DashboardCard>();
        if (string.IsNullOrWhiteSpace(entry.Text))
        {
            screenLabel.Text = screenLabelString;
            CourseCatalogSearchListView.IsVisible = false;
            CourseCatalogListView.IsVisible = true;
        }
        else
        {
            screenLabel.Text = "Search Course";
            foreach (DashboardCard card in allListData)
            {
                var courseCode = card.Course;
                if (courseCode.ToLower().Contains(entry.Text.ToLower()))
                {
                    searchListData.Add(card);
                }
            }
            searchListData = new ObservableCollection<DashboardCard>(allListData.Where(i =>
                (i is DashboardCard && (((DashboardCard) i).Course.ToLower().Contains(entry.Text.ToLower())))));
            CourseCatalogSearchListView.ItemsSource = searchListData;
            CourseCatalogSearchListView.IsVisible = true;
            CourseCatalogListView.IsVisible = false;
        }
        Console.WriteLine(searchListData.Count);
    }
    void Menu_Button_Clicked(object sender, System.EventArgs e)
    {
        Navigation.PushModalAsync(new MenuPage());
        //
    }
    async void Filter_Handle_Clicked(object sender, System.EventArgs e)
    {
        if (!CourseCatalogSearchListView.IsVisible)
        {
            var page = new CourseCatalogFilterPopup(this);
            await PopupNavigation.Instance.PushAsync(page);
        }
        else
        {
            await DisplayAlert(AppConstants.AppName, "Please Close the Search to access Filter",
                AppConstants.OK);
        }
    }
    async void Filter_three_dot_Handle_Clicked(object sender, System.EventArgs e)
    {
        var page = new CourseCatalogMorePopup();
        await PopupNavigation.Instance.PushAsync(page);
    }
   async void Course_List_ItemSelected(object sender, Xamarin.Forms.SelectedItemChangedEventArgs e)
    {
        DashboardCard dashboardCard = (DashboardCard)e.SelectedItem;
        if (!dashboardCard.Status.Equals("TAKEN") &&
            !dashboardCard.Status.Equals("EQUIV") &&
            !dashboardCard.Status.Equals("SKILL") &&
            !dashboardCard.Pending.Equals("WRA") &&
            dashboardCard.SelfTrain.Equals("Y"))
        {
            var page = new SelfTrainBasePage(dashboardCard);
            await Navigation.PushModalAsync(page);
        }
        else
        {
            await DisplayAlert("iSOTrain", "Yet to be implemented.", "OK");
        }
    }
    async void Course_Search_List_ItemSelected(object sender, Xamarin.Forms.SelectedItemChangedEventArgs e)
    {
        DashboardCard dashboardCard = (DashboardCard)e.SelectedItem;
        if (!dashboardCard.Status.Equals("TAKEN") &&
            !dashboardCard.Status.Equals("EQUIV") &&
            !dashboardCard.Status.Equals("SKILL") &&
            !dashboardCard.Pending.Equals("WRA") &&
            dashboardCard.SelfTrain.Equals("Y"))
        {
            var page = new SelfTrainBasePage(dashboardCard);
            await Navigation.PushModalAsync(page);
        }
        else
        {
            await DisplayAlert("iSOTrain", "Yet to be implemented.", "OK");
        }
    }

    public void UpdateCourseCatalagListContent()
    {
        _expandedGroups = new ObservableCollection<CourseCatalogModel>();
        foreach (CourseCatalogModel group in _allGroups)
        {
            //Create new FoodGroups so we do not alter original list
            CourseCatalogModel newGroup = new CourseCatalogModel(group.Title, group.Expanded);
            newGroup.DataCount = group.Count;
            //Add the count of food items for Lits Header Titles to use
            if (group.Expanded)
            {
                foreach (DashboardCard dataModel in group)
                {
                    newGroup.Add(dataModel);
                }
            }
            _expandedGroups.Add(newGroup);
        }
        CourseCatalogListView.ItemsSource = _expandedGroups;
    }
}

谁能告诉我如何在每次页面加载时重置视图模型?

您可以在每次页面加载OnAppearing重置数据,我推荐两种刷新数据的方法。

1.重置_allGroups中的models

2.复位_allGroups

public partial class MainPage : ContentPage
{
    public ObservableCollection<CourseCatalogModel> _allGroups;
    public MainPage()
    {
        InitializeComponent();
        _allGroups = new ObservableCollection<CourseCatalogModel>();
    }
    protected override void OnAppearing()
    {
        base.OnAppearing();
        //1. reset your properties in _allGroups 
        foreach (var CourseCatalogModel in _allGroups)
        {
            CourseCatalogModel.Expanded = false;
            //...reset  if you have other properties
        }

        //2.create a new _allGroup everytime load page
        _allGroups = new ObservableCollection<CourseCatalogModel>();
        //.... Add data to _allGroups
        _allGroups.Add(new CourseCatalogModel());
        ...
    }
}

尝试初始化您的_allGroups如下所示:

 ObservableCollection<CourseCatalogModel>
            _allGroups = new ObservableCollection<CourseCatalogModel>();
        foreach (var CourseCatalogModel in CourseCatalogModel.CourseCatalogAll)
        {
            _allGroups.Add(CourseCatalogModel);
        }

最后我搞定了。.问题出在静态方法上。我的模型类方法我创建为静态,它们只被调用一次,这就是数据不刷新的原因。

这里是模型类的代码。

 public class CourseCatalogModel : ObservableCollection<DashboardCard>, INotifyPropertyChanged
{
    private bool _expanded;
    public string Title { get; set; }
    private int _dataCount;
    public int DataCount
    {
        get { return _dataCount; }
        set
        {
            if (_dataCount != value)
            {
                _dataCount = value;
                OnPropertyChanged("StateIcon");
                OnPropertyChanged("TitleColor");
            }
        }
    }
    public string TitleColor
    {
        get
        {
            if (DataCount == 0)
            {
                return "#FFAEB2B5";
            }
            return "#FF00588A";
        }
    }

    public bool Expanded
    {
        get { return _expanded; }
        set
        {
            if (_expanded != value)
            {
                _expanded = value;
                OnPropertyChanged("Expanded");
                OnPropertyChanged("StateIcon");
            }
        }
    }

    public string StateIcon
    {
        get
        {
            if (DataCount == 0)
            {
                return "expand_empty";
            }
            return Expanded ? "expand_iCon.png" : "collapse_icon.png";
        }
    }
    public CourseCatalogModel(string title, bool expanded = true)
    {
        Title = title;
        Expanded = expanded;
    }
    public  ObservableCollection<CourseCatalogModel> CourseCatalogAll { private set; get; }
    public  ObservableCollection<CourseCatalogModel> CourseCatalogRequired { private set; get; }
    public  ObservableCollection<CourseCatalogModel> CourseCatalogNotRequired { private set; get; }
     public CourseCatalogModel()
    {
        // Course Awaiting Approvel...
        CourseCatalogModel awaitingApprovel = new CourseCatalogModel("Awaiting Approval", false);
        var awaitingCards = CourseCatalogModuleHelper.GetAwaitingApprovels();
        foreach (var dashboardCard in awaitingCards)
        {
            awaitingApprovel.Add(dashboardCard);
        }
        // Course Pending Courses...
        CourseCatalogModel pendingCourses = new CourseCatalogModel("Pending Courses", false);
        var pendingCourseCards = CourseCatalogModuleHelper.GetPendingCourses();
        foreach (var dashboardCard in pendingCourseCards)
        {
            pendingCourses.Add(dashboardCard);
        }
        // Course Completed Courses...
        CourseCatalogModel completedCourses = new CourseCatalogModel("Completed Courses", false);
        var completedCourseCards = CourseCatalogModuleHelper.GetCompletedCourses();
        foreach (var dashboardCard in completedCourseCards)
        {
            completedCourses.Add(dashboardCard);
        }
        ObservableCollection<CourseCatalogModel>
            CourseCatalogdata = new ObservableCollection<CourseCatalogModel>();
        CourseCatalogdata.Add(awaitingApprovel);
        CourseCatalogdata.Add(pendingCourses);
        CourseCatalogdata.Add(completedCourses);
        CourseCatalogAll = new ObservableCollection<CourseCatalogModel>();
        CourseCatalogAll = CourseCatalogdata;
        GetRequiredCourseCatalogCards();
        GetNotRequiredCourseCatalogCards();
    }
    private  void GetRequiredCourseCatalogCards()
    {
        // Course Awaiting Approvel...
        CourseCatalogModel awaitingApprovel = new CourseCatalogModel("Awaiting Approval", false);
        var awaitingCards = CourseCatalogModuleHelper.GetAwaitingApprovels(AppConstants.CourseFilterRequired);
        foreach (var dashboardCard in awaitingCards)
        {
            awaitingApprovel.Add(dashboardCard);
        }
        // Course Pending Courses...
        CourseCatalogModel pendingCourses = new CourseCatalogModel("Pending Courses", false);
        var pendingCourseCards = CourseCatalogModuleHelper.GetPendingCourses(AppConstants.CourseFilterRequired);
        foreach (var dashboardCard in pendingCourseCards)
        {
            pendingCourses.Add(dashboardCard);
        }
        // Course Completed Courses...
        CourseCatalogModel completedCourses = new CourseCatalogModel("Completed Courses", false);
        var completedCourseCards = CourseCatalogModuleHelper.GetCompletedCourses(AppConstants.CourseFilterRequired);
        foreach (var dashboardCard in completedCourseCards)
        {
            completedCourses.Add(dashboardCard);
        }
        ObservableCollection<CourseCatalogModel>
            CourseCatalogdata = new ObservableCollection<CourseCatalogModel>();
        CourseCatalogdata.Add(awaitingApprovel);
        CourseCatalogdata.Add(pendingCourses);
        CourseCatalogdata.Add(completedCourses);
        CourseCatalogRequired = CourseCatalogdata;
    }
    private  void GetNotRequiredCourseCatalogCards()
    {
        // Course Awaiting Approvel...
        CourseCatalogModel awaitingApprovel = new CourseCatalogModel("Awaiting Approval", false);
        var awaitingCards = CourseCatalogModuleHelper.GetAwaitingApprovels(AppConstants.CourseFilterNotRequired);
        foreach (var dashboardCard in awaitingCards)
        {
            awaitingApprovel.Add(dashboardCard);
        }
        // Course Pending Courses...
        CourseCatalogModel pendingCourses = new CourseCatalogModel("Pending Courses", false);
        var pendingCourseCards = CourseCatalogModuleHelper.GetPendingCourses(AppConstants.CourseFilterNotRequired);
        foreach (var dashboardCard in pendingCourseCards)
        {
            pendingCourses.Add(dashboardCard);
        }
        // Course Completed Courses...
        CourseCatalogModel completedCourses = new CourseCatalogModel("Completed Courses", false);
        var completedCourseCards = CourseCatalogModuleHelper.GetCompletedCourses(AppConstants.CourseFilterNotRequired);
        foreach (var dashboardCard in completedCourseCards)
        {
            completedCourses.Add(dashboardCard);
        }
        ObservableCollection<CourseCatalogModel>
            CourseCatalogdata = new ObservableCollection<CourseCatalogModel>();
        CourseCatalogdata.Add(awaitingApprovel);
        CourseCatalogdata.Add(pendingCourses);
        CourseCatalogdata.Add(completedCourses);
        CourseCatalogNotRequired = CourseCatalogdata;
    }
    public event PropertyChangedEventHandler PropertyChanged;
    protected virtual void OnPropertyChanged(string propertyName)
    {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }
}

这是我的班级

 public partial class CourseCatalogBaseClass : ContentPage
{
    public ObservableCollection<CourseCatalogModel> _allGroups  = new ObservableCollection<CourseCatalogModel>();
    ObservableCollection<CourseCatalogModel> _expandedGroups = new ObservableCollection<CourseCatalogModel>();
    List<DashboardCard> allListData = new List<DashboardCard>();
    CourseCatalogModel courseCatalogModel = new CourseCatalogModel();
    ObservableCollection<DashboardCard> searchListData =  new ObservableCollection<DashboardCard>();
    private string screenLabelString = string.Empty;
    public ObservableCollection<FilterPopupModel> courseFilterPopupModels = new ObservableCollection<FilterPopupModel>();
    public CourseCatalogBaseClass(bool isFromQualifications = false)
    {
        InitializeComponent();
        if (isFromQualifications)
        {
            screenLabel.Text = "My Qualifications";
            screenLabelString = screenLabel.Text;
        }

        allListData = App.DashboardResponse.TrainingContentCards;
        CourseCatalogSearchListView.IsVisible = false;


        //2.create a new _allGroup everytime load page
        _allGroups = new ObservableCollection<CourseCatalogModel>();
        //.... Add data to _allGroups
        foreach (CourseCatalogModel CourseCatalogModel in courseCatalogModel.CourseCatalogAll)
        {
            _allGroups.Add(CourseCatalogModel);
        }
        //1. reset your properties in _allGroups 
        foreach (var CourseCatalogModel in _allGroups)
        {
            CourseCatalogModel.Expanded = false;
            //...reset  if you have other properties
        }
        CourseCatalogSearchListView.IsVisible = false;
        UpdateCourseCatalagListContent();
        InitilizeFilters();
    }
    protected override void OnAppearing()
    {
        base.OnAppearing();


}
    private void InitilizeFilters()
    {
        courseFilterPopupModels.Add(new FilterPopupModel()
        { Title = "All Classes", TitleColor = Color.FromHex("#00588A") });
        courseFilterPopupModels.Add(new FilterPopupModel()
        { Title = "Required", TitleColor = Color.FromHex("#686868") });
        courseFilterPopupModels.Add(new FilterPopupModel()
        { Title = "Not Required", TitleColor = Color.FromHex("#686868") });
        courseFilterPopupModels.Add(new FilterPopupModel() { Title = "Help", TitleColor = Color.FromHex("#686868") });
    }
    private void CourseListHeaderTapped(object sender, EventArgs args)
    {
        int selectedIndex = _expandedGroups.IndexOf(
            ((CourseCatalogModel)((Button)sender).CommandParameter));
        _allGroups[selectedIndex].Expanded = !_allGroups[selectedIndex].Expanded;
        UpdateCourseCatalagListContent();
    }
    void Handle_Search_Bar_TextChanged(object sender, Xamarin.Forms.TextChangedEventArgs e)
    {
        var entry = (Entry)sender;
        searchListData = new ObservableCollection<DashboardCard>();
        if (string.IsNullOrWhiteSpace(entry.Text))
        {
            screenLabel.Text = screenLabelString;
            CourseCatalogSearchListView.IsVisible = false;
            CourseCatalogListView.IsVisible = true;
        }
        else
        {
            screenLabel.Text = "Search Course";
            foreach (DashboardCard card in allListData)
            {
                var courseCode = card.Course;
                if (courseCode.ToLower().Contains(entry.Text.ToLower()))
                {
                    searchListData.Add(card);
                }
            }
            searchListData = new ObservableCollection<DashboardCard>(allListData.Where(i =>
                (i is DashboardCard && (((DashboardCard)i).Course.ToLower().Contains(entry.Text.ToLower())))));
            CourseCatalogSearchListView.ItemsSource = searchListData;
            CourseCatalogSearchListView.IsVisible = true;
            CourseCatalogListView.IsVisible = false;
        }
        Console.WriteLine(searchListData.Count);
    }
    void Menu_Button_Clicked(object sender, System.EventArgs e)
    {
        Navigation.PushModalAsync(new MenuPage());
        //
    }
    async void Filter_Handle_Clicked(object sender, System.EventArgs e)
    {
        if (!CourseCatalogSearchListView.IsVisible)
        {
            var page = new CourseCatalogFilterPopup(this);
            await PopupNavigation.Instance.PushAsync(page);
        }
        else
        {
            await DisplayAlert(AppConstants.AppName, "Please Close the Search to access Filter",
                AppConstants.OK);
        }
    }
    async void Filter_three_dot_Handle_Clicked(object sender, System.EventArgs e)
    {
        var page = new CourseCatalogMorePopup();
        await PopupNavigation.Instance.PushAsync(page);
    }
    async void Course_List_ItemSelected(object sender, Xamarin.Forms.SelectedItemChangedEventArgs e)
    {
        DashboardCard dashboardCard = (DashboardCard)e.SelectedItem;
        if (!dashboardCard.Status.Equals("TAKEN") &&
            !dashboardCard.Status.Equals("EQUIV") &&
            !dashboardCard.Status.Equals("SKILL") &&
            !dashboardCard.Pending.Equals("WRA") &&
            dashboardCard.SelfTrain.Equals("Y"))
        {
            var page = new SelfTrainBasePage(dashboardCard);
            await Navigation.PushModalAsync(page);
        }
        else
        {
            await DisplayAlert("iSOTrain", "Yet to be implemented.", "OK");
        }
    }
    async void Course_Search_List_ItemSelected(object sender, Xamarin.Forms.SelectedItemChangedEventArgs e)
    {
        DashboardCard dashboardCard = (DashboardCard)e.SelectedItem;
        if (!dashboardCard.Status.Equals("TAKEN") &&
            !dashboardCard.Status.Equals("EQUIV") &&
            !dashboardCard.Status.Equals("SKILL") &&
            !dashboardCard.Pending.Equals("WRA") &&
            dashboardCard.SelfTrain.Equals("Y"))
        {
            var page = new SelfTrainBasePage(dashboardCard);
            await Navigation.PushModalAsync(page);
        }
        else
        {
            await DisplayAlert("iSOTrain", "Yet to be implemented.", "OK");
        }
    }

    public void UpdateCourseCatalagListContent()
    {
        _expandedGroups = new ObservableCollection<CourseCatalogModel>();
        foreach (CourseCatalogModel group in _allGroups)
        {
            //Create new FoodGroups so we do not alter original list
            CourseCatalogModel newGroup = new CourseCatalogModel(group.Title, group.Expanded);
            newGroup.DataCount = group.Count;
            //Add the count of food items for Lits Header Titles to use
            if (group.Expanded)
            {
                foreach (DashboardCard dataModel in group)
                {
                    newGroup.Add(dataModel);
                }
            }
            _expandedGroups.Add(newGroup);
        }
        CourseCatalogListView.ItemsSource = _expandedGroups;
    }
}

最新更新