0

I made a solution wich contains 4 projects, UI, BL, DAL and BO.

  • UI : usercontrols, windows.
  • BL : some logics, and a static class.
  • Dal : a static class repository.
  • BO : my objects ( Person, ...)

The first 3 projects have reference to BO project, and UI refer to BL and BL to DAL. In BL project I have a Collection, and in my UI (in a ViewModel) I have an ObservableCollection, the problem is the binding between these 2 Collections, for example, when I want to add a person, I have to do like that :

BL.Persons.Add( new Person() { Name = "Paul"});
this.Persons = new ObservableCollection<Person>(BL.Persons);

it works, but I'm not sure if it's the best way.

4

1 回答 1

0

ObservableCollection你不应该每次都重新创建你的。在这种情况下没有意义,因为ObservableCollection应该通知观察者有关更改。当然,这是因为发生了Persons变化而起作用,但是对于较大的集合来说效率非常低,因为它会表现得好像每个对象都发生了变化,但实际上只添加了一个新对象。

这对你更好:

var person = new Person() { Name = "Paul"};
BL.Persons.Add(person);
this.Persons.Add(person);

顺便说一句,我不喜欢这种模型/视图模型混合,如果你只将视图模型暴露给你的视图会更好干净,但这是一个不同的问题。

于 2012-10-31T12:06:24.117 回答