WPF 数据绑定:如何在解决方案中组织项目和类?

发布于 2024-10-03 15:39:33 字数 1388 浏览 3 评论 0原文

我的解决方案中有以下项目/程序集:

  1. 实体;它是一个类库,包含两个类:AccountAccountDetailAccount 类有一个 ObservableCollection 类型的属性 Details,我用它来存储帐户对象的详细信息。
  2. 核心;它是一个类库,包含一个类:AccountController,其目的是从 Sql Server 获取数据并填充 Account 对象(以及其中的 AccountDetail 集合) 。
  3. ;它是一个 WPF 应用程序项目,包含一个名为:AccountsWindow 的 WPF 表单,其目的是显示从 Sql Server Gui.Controller 检索到的所有帐户的列表
  4. ;它是一个类库,包含一个类:AccountWindowController,它应该是 Core 程序集中的 AccountController 和来自 Gui 程序集的 AccountsWindow 并协助数据绑定。 (我不确定我是否需要这个程序集。)

这就是我想要做的:

我想使用 CoreAccountController 类从 Sql Server 获取所有帐户code> assembly 并将它们放入某个列表中。然后,我想将 AccountWindow 中的列表框与该帐户列表进行数据绑定。

我的问题:

  1. 我应该将该帐户列表放在 AccountWindowController 或 其他地方?
  2. 该列表应该是 ObservableCollection 类型吗?
  3. 我真的需要那个账户列表吗?
  4. 数据绑定时,我应该从 Gui.Controller 创建一个 Window.Resource 还是 实体类?

我知道要阅读的文字很多,但我的问题非常简单,因为我是 WPF 的新手,任何帮助将不胜感激。谢谢!

更新:我的痛苦继续这里。干杯!

I have the following projects/assemblies in my solution:

  1. Entities; It is a class library that contains two classes: Account and AccountDetail. Account class has a property Details which is of type ObservableCollection<AccountDetail> and I use it to store the details of the account object.
  2. 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 the Account objects (alongside the AccountDetail collection within them).
  3. 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
  4. Gui.Controller; It is a class library that contains one class: AccountWindowController which is supposed to be the "bridge" between the AccountController from the Core assembly and the AccountsWindow from the Gui 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:

  1. Where should I placed that list of accounts, in the AccountWindowController or
    somewhere else?
  2. Should that list be of a type ObservableCollection?
  3. Do I need that list of accounts at all?
  4. When data binding, should I create a Window.Resource from the Gui.Controller or
    Entities 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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜无邪 2024-10-10 15:39:33

看来您的 Gui 将成为客户端,并将引用其他 3 个程序集。 Gui.Controller 将引用 Core 和 DataEntities,而 Core 将仅引用 DataEntities。

AccountController 应该获取列表并将其返回给 Gui.Controller。如果列表是 ObservableCollection 就可以了。列表本身应该放置在 Gui 或 Gui.Controller 中,具体取决于您是否可以从 Gui 访问 Gui.Controller 的属性。
当您将 ListBox 放入要放置在 Gui 中的 Window 中时,您需要将其绑定到集合。该集合可以是 Window 的属性。或者您可以将其绑定到一个方法,该方法可以是 Gui.Controller 的一部分。这实际上取决于您想要如何组织它。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文