我对 MVVM 模式感到困惑。实际上,我有 ViewModel,其中我有一个 ObservableCollection,这里的 AssignmentClass 与模型分配的相同,但 AssignmentClass 中有 NotifypropertyChanged。所以我的问题是我可以在模型上实现 INotifypropertyChanged,这样我就不必创建另一个类(AssignmentClass),根据 MVVM 模式是否正确。
我的模型是
public class assignment
{
public int id { get; set; }
public string title { get; set; }
public string app_id { get; set; }
public string student_asg_status { get; set; }
public string teacher_id { get; set; }
public string teacher_name { get; set; }
public string asg_status { get; set; }
public string sdate { get; set; }
public string edate { get; set; }
public string creation_date { get; set; }
public string mod_date { get; set; }
public string app_title { get; set; }
public int category_id { get; set; }
public string app_category { get; set; }
public string cover { get; set; }
public string icon { get; set; }
public string settings { get; set; }
public string isenddatedefault { get; set; }
public string isstartdatedefault { get; set; }
public bool isdraft { get; set; }
}
我的 AssignmentClass 具有所有相同的属性,但 NotifyPropertyChanged..on 属性 id 是..
private int _id;
public int id
{
get
{
return _id;
}
set
{
_id = value;
RaisePropertyChanged("id");
}
}
在我的视图模型中,我像这样收集..
AssignmentCollection = new ObservableCollection<AssignmentClass>();
var lst = await App.conn.QueryAsync<assignment>("SELECT * FROM assignment;");
for (int i = 0; i < 6; i++)
{
AssignmentClass asd = new AssignmentClass();
asd.id= lst[i].id;
AssignmentCollection.Add(asd);
}
我可以在模型分配上像这样收集我的收藏吗..如果它实现了 propertychanged..
AssignmentCollection = new ObservableCollection<assignment>();