У меня есть проект MVP MVP, который я работаю, я использую призму, чтобы INotifyPropertyChanged = SetProperty. У меня есть модель, которая ComplaintModel:WPF Listview не отображает список
public class ComplaintModel:BindableBase, IDataErrorInfo
{
private Person _complaintPerson;
private List<EmployeeModel> _crewList;
public string MyStreet { get; set; }
public string Complaint { get; set; }
public string Response { get; set; }
public DateTime? DateOfResponse { get; set; }
public DateTime EntryDate { get; set; }
public bool? Callout { get; set; }
public string Quad { get; set; }
public string Tap { get; set; }
public DateTime? Modified { get; set; }
public Person ComplaintPerson
{
get { return _complaintPerson; }
set { SetProperty(ref (_complaintPerson), value); }
}
public List<EmployeeModel> CrewList
{
get { return _crewList; }
set { SetProperty(ref (_crewList), value); }
}
public int ComplaintID { get; set; }
и свойство в ViewModel:
private ComplaintModel _selectedComplaint;
public ComplaintModel SelectedComplaint
{
get { return _selectedComplaint; }
set { SetProperty(ref (_selectedComplaint), value); }
}
EmployeeModel является
public class EmployeeModel:BindableBase,IDataErrorInfo
{
private string _phone;
private string _firstName;
private string _lastName;
public int Id { get; set; }
public string FirstName
{
get { return _firstName; }
set { SetProperty(ref(_firstName),value); }
}
public string LastName
{
get { return _lastName; }
set { SetProperty(ref(_lastName),value); }
}
public string Phone
{
get { return _phone; }
set { SetProperty(ref (_phone), value); }
}
Поэтому я стараюсь addEmployee:
private void AddEmployee()
{
if (SelectedEmployee == null)
{
SetMessage(Messages.ChooseEmployeeMessage);
return;
}
if (IsReadOnly)
{
SetMessage(Messages.MakeEditableMessage);
return;
}
if (SelectedComplaint.CrewList == null)
{
SelectedComplaint.CrewList = new List<EmployeeModel>();
}
var myList = SelectedComplaint.CrewList;
var employee = new EmployeeModel() {FirstName = "James", Id = 1, LastName = "Tays", Phone = "1234567"};
myList.Add(employee);
employee = new EmployeeModel() { FirstName = "John", Id = 2, LastName = "Doe", Phone = "1234567" };
myList.Add(employee);
SelectedComplaint.CrewList = myList;
SelectedEmployee = null;
}
Это добавляет два e mworksees в CrewList, но не обновляет представление. Самое смешное, когда я меняю var myList = SelectedComplaint.CrewList
на var myList = new List<EmployeeModel>();
, он добавит 2 сотрудников и обновит представление. Я также пробовал SelectedComplaint.CrewList.Add(employee)
, и это не обновляло представление.
, пожалуйста, дайте мне знать, если вы видите область, которую я пропустил.
спасибо, что сделал! :) – JamTay317