WPF数据绑定:如何在解决方案中组织项目和类? [英] WPF Data binding: How to organize projects and classes in a solution?

查看:183
本文介绍了WPF数据绑定:如何在解决方案中组织项目和类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have the following projects/assemblies in my solution:


  1. 实体它是一个类库,包含两个类:帐户 AccountDetail 帐户类具有一个属性详细信息,类型为 ObservableCollection< AccountDetail> ,我用它来存储帐号对象

  2. 核心;它是一个类库,其中包含一个类: AccountController ,其目的是从Sql Server获取数据并填充帐户对象(在其中的AccountDetail集合旁边)。

  3. Gui ;它是一个WPF应用程序项目,其中包含一个名为: AccountsWindow 的WPF窗体,其目的是显示从Sql Server检索到的所有帐户的列表

  4. Gui.Controller ;它是一个类库,它包含一个类: AccountWindowController ,它应该是 AccountController 之间的桥 Core 程序集和 AccountsWindow Gui 程序集和协助数据绑定。 (我不知道我是否需要这个程序集。)

  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.)

这是我要做的:

我想从 Core AccountController 类从Sql Server中获取所有帐户c>汇编并将它们放在一些列表中。然后,我想使用该列表的数据绑定 AccountWindow 中的列表框。

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.

我的问题:


  1. 我应该在哪里放置该帐户列表?

  2. 我需要帐号列表吗?

  3. 当数据绑定时,应该从 Gui.Controller Window.Resource $ c $或
    实体类?

  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?

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

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!

推荐答案

似乎你的Gui将是客户端,并将引用其他3个程序集。 Gui.Controller将引用Core和DataEntities,Core将仅引用DataEntities。

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.

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

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.

这篇关于WPF数据绑定:如何在解决方案中组织项目和类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆