WPF data binding: how to organize projects and classes in a solution?

I have the following projects / assemblies in my solution:

  • Entities This is a class library that contains two classes: Account and AccountDetail . Account class has a Details property, which is of type ObservableCollection<AccountDetail> , and I use it to store information about the account object.
  • Core This is a class library that contains one class: AccountController , the purpose of which is to obtain data from the Sql server and populate Account objects (along with the AccountDetail collection inside them).
  • Gui This is a WPF application project containing one WPF form called AccountsWindow , the purpose of which is to list all the accounts received from the Sql server
  • Gui.Controller ; This is a class library that contains one class: AccountWindowController , which should be the "bridge" between the AccountController from the Core assembly and AccountsWindow from the Gui assembly and to help data binding. (I'm not sure if I need this assembly at all.)

Here is what I want to do:

I want to get all the accounts from the Sql server using the AccountController class from the Core assembly and put them in some list. Then I want to bind data to a list in AccountWindow with this list of accounts.

My questions:

  • Where should I place this list of accounts in AccountWindowController or somewhere else?
  • Should this list be of type ObservableCollection ?
  • Do I need this list of accounts?
  • When linking data, should I create Window.Resource from Gui.Controller or Entities classes?

I know this is a lot of text to read, but my questions are very simple since I am new to WPF and any help would be greatly appreciated. Thanks!

Update: Agony continues here . Hooray!

0
data-binding code-organization wpf project-organization
source share
1 answer

It seems your Gui will be the client and will reference the other 3 builds. Gui.Controller will reference Core and DataEntities, and Core will only reference DataEntities.

AccountController should get the list and return it to Gui.Controller. It’s good if there is an ObservableCollection in the list. The list itself must be placed in Gui or Gui.Controller, depending on whether you can access the Gui.Controller properties from Gui. When you put a ListBox in a window that will be placed in Gui, you need to bind it to the collection. A collection may be a window property. Or you can bind it to a method that can be part of Gui.Controller. It really depends on how you want to organize it.

0
source share

All Articles