【发布时间】:2014-07-01 13:07:57
【问题描述】:
我有问题。 我有一个绑定到“Patient_view”的数据网格:
private ObservableCollection<pViewModel> patient_view;
public ObservableCollection<pViewModel> Patient_view
{
get
{
return patient_view;
}
set
{
if (Patient_view != value)
{
patient_view = value;
this.NotifyPropertyChanged("Patient_view");
}
}
}
如果我启动我的程序,数据网格会显示此查询的查询结果:
public static IList<Patient_Anschrift_List> Patients { get; private set; }
static PatientList()
{
using (dbentities context = new dbentities())
{
Patients = new List<Patient_Anschrift_List>();
Patients = (from p in ..
select new Patient_Anschrift_List()
{..}
}
好的,没关系。但是现在我想使用其他一些查询(它们已经编写好了。我的程序基本上已经可以工作了,但是必须将其放入 mvvm 模式中,这对我来说很难,因为我没有真正的编程经验)。
我的问题是,数据网格不显示其他查询结果。 在启动时它会充满:
public pViewModelList()
{
patient_view = new ObservableCollection<pViewModel>(PatientList.Patients.Select(p => new pViewModel(p)));
//patients.CollectionChanged += Patients_AddCollection;
}
但如果我尝试在按钮按下时更改集合,它就不会做任何事情。它一直显示旧的结果。 这就是我在按钮按下时所做的:
private void ExecuteAddPatientCommand()
{
// Patients.Add(new pViewModel(new Patient()));
Abfragen abfragen = new Abfragen();
Eingaben_prüfen p = new Eingaben_prüfen();
List<Patient_Anschrift_List> ausgabe = new List<Patient_Anschrift_List>();
ausgabe = abfragen.select_Patients(p.Nachname(eingabe1), p.Vorname(eingabe1), p.Versichertenstatus(eingabe1)...);
// patient_view.Clear();
patient_view = new ObservableCollection<pViewModel>(ausgabe.Select(s => new pViewModel(s)));
如果我这样做:
patient_view.Add(new pViewModel(new dModel.Patient_Anschrift_List{Nachname ="test", Vorname = "test"}));
它不是选择,而是添加一个新行并立即在网格中显示它。
你能告诉我我做错了什么吗? 你需要更多细节吗? 谢谢你 (希望你能理解我的英语)
【问题讨论】:
-
你设置了双向绑定模型了吗?
-
是的,我就是这样绑定的:
-
ItemsSource="{Binding Patient_view,Mode=TwoWay}"
-
Jup,吃到了。只是复制了错误的东西:D(如果有影响,请拿出来测试一下)
-
然后显式调用 notifyproperty 更改为 NotifyPropertyChanged("Patient_view");更改 Patient_view 后