Xamarin开发人员,
在一个类中,我有一个listView,并且从ViewModel获取数据。因此,当用户按下页眉时,我正在扩展列表,并且在更改 expand Variable 的值。当我下次加载页面时,也该 expand Variable 。 value仍然为true,默认情况下,列表会被扩展。有人可以告诉我如何在每次页面加载时重设ResetViewModel吗?
我的模型班。
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;
}
}
答案 0 :(得分:1)
有人可以告诉我如何在每次页面加载时重置ViewModel吗?
每次页面加载时,您都可以在OnAppearing
中重置数据,我建议两种刷新数据的方法。
1。在models
中重置_allGroups
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);
}
答案 1 :(得分:0)
最后我钉了它。问题出在静态方法上。我创建的Model类方法是静态的,并且只调用了一次,这就是为什么数据没有刷新的原因。
这里是Model类的代码。
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;
}
}