I have the following projects/assemblies in my solution:
- Entities; It is a class library that contains two classes:
Account
andAccountDetail
.Account
class has a property Details which is of typeObservableCollection<AccountDetail>
and I use it to store the details of the account object. - Core; It is a class library that contains one class:
AccountController
whose purpose is to get the data from the Sql Server and to populate theAccount
objects (alongside the AccountDetail collection within them). - Gui; It is a WPF Application project that contains one WPF Form called:
AccountsWindow
whose purpose is to present the list of all accounts retrieved from the Sql Server - Gui.Controller; It is a class library that contains one class:
AccountWindowController
which is supposed to be the "bridge" between theAccountController
from theCore
assembly and theAccountsWindow
from theGui
assembly and to assist with the data binding. (I am not sure whether I need this assembly at all.)
Here's what I wish to do:
I want to get all accounts from the Sql Server using the AccountController
class from the Core
assembly and to put them in some list. Then, I want to data bind a list box in AccountWindow
with that list of accounts.
My questions:
- Where should I placed that list of accounts, in the
AccountWindowController
or somewhere else? - Should that list be of a type
ObservableCollection
? - Do I need that list of accounts at all?
- When data binding, should I create a
Window.Resource
from theGui.Controller
orEntities
classes?
开发者_如何学编程I know this is a lot of text to read, but my questions are really simple as I am a newbie with the WPF and any help would be greatly appreciated. Thanks!
Update: My agony is continued here. Cheers!
It seems your Gui will be the client and will Reference the other 3 assemblies. Gui.Controller will reference Core and DataEntities, and Core will reference only DataEntities.
The AccountController should fetch the list and return it to the Gui.Controller. It's fine if the list is ObservableCollection. The list itself should be placed in the Gui or Gui.Controller, depending if you can access the properties of Gui.Controller from Gui. When you put the ListBox in a Window which will be placed in the Gui, you need to bind it to a collection. The collection can be a property of the Window. Or you can bind it to a method, which can be part of Gui.Controller. It really depends on how you want to organize it.
精彩评论