基于 XML 的元数据驱动的 WPF 应用程序
我正在 WPF 中开发 BI 应用程序。我正在设计其架构,并正在寻找一种将视图中的控件直接绑定到包含视图元数据的 xml 的方法。你认为这可能吗?那怎么办?或者是否建议从 xml 中读取并相应地生成视图?
已编辑
图表颜色、图表创建者、向下钻取图表时的下一个图表、用户名及其密码、用户组名称等属性存储在 XML 文件中。当用户启动应用程序时,应显示他创建的仪表板;这是通过从后端检索数据并分配正确的图表颜色来实现的。因此,如果这些数据在 XML 中可用,我的问题是根据用户请求生成图表和仪表板的最佳方法。
已编辑
正如我之前所解释的,问题是以最有效和结构化的方式存储与此应用程序相关的元数据,以便在用户登录时回调。
提前致谢。
I am working on a BI application in WPF. I am in the process of designing its architecture and am in search of a way to directly bind controls in the view to a xml which contains the metadata of the view. Do you think this is going to be possible? then how? or is it advisable to read off from the xml and generate the views accordingly?
Edited
Properties such as colors of charts, who created the chart, the next chart upon drilling down a chart, the user names and their passwords, user group names etc. are stored in XML files. When a user starts the application the dashboards he has created should be displayed; this happens with the retrieval of data from the back end and by assigning the correct chart colors. So if these data are available in the XML, my question is the best way to generate the charts and dashboards upon user request.
Edited
As I explained earlier as well, the problem is to store the metadata related to this application in the most efficient and structured way to call back upon a user loging in.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不确定我是否完全理解你想要做什么。如果您只想将一些 UI 控件属性绑定到 XML 文档中的数据,这是完全可能的。几年前我在这里写过关于它的博客。
I'm not sure I quite understand what you are looking to do. If you just want to bind some UI control properties to data in an XML document, that's entirely possible. I blogged about it years ago here.
我建议使用 XAML 而不是 XML。
XAML 不仅允许您定义 UI,而且 XAML 还可以包含其他元数据或配置信息,您可以以 XAML 的形式直接读取/写入 CLR 类。
是,
例如,
您的 Screen xaml 看起来像
您可以创建 XAML 资源并加载它,就像...
I will suggest use of XAML instead of XML.
XAML will not only let you define the UI but XAML also can contain your other metadata or config information that you can read/write in the form of XAML to directly your CLR class.
Benefits are,
For example,
And your Screen xaml can look like
You can create XAML resource and load it like...
我认为在您的情况下最好的方法是按数据类(元类型)划分系统中所有可能的数据。之后,在 xml 中指定数据元类型,以便您的数据始终具有元类型。在创建视图之前,您应该读取要显示的数据的所有元类型,并根据该元类型创建屏幕控件。之后您可以加载并显示数据。这种方法在我的小程序中效果很好,我认为它也会在您的系统中产生良好的结果。
[编辑]
好的,您的应用程序包括业务域(您的业务数据、业务逻辑和数据显示规则)。所有这些东西都分布在三个部分中:模型、视图和视图模型。据我正确理解,您的问题是关于 ViewModel 的。
例如,您假设的应用程序包含员工信息,并假设每个员工可能拥有三类有关他或她的信息:
所以我们有域 - 员工。该域可以分为三个元类型:
对于每个元类型,我们应该创建子屏幕,该子屏幕将根据业务规则显示元类型信息。我会建议您使用 MVC 模式制作元类型子屏幕,因为在编辑数据时可能会应用一些特殊的编辑规则或数据验证。当我们创建每个子屏幕时,我们可以自由地显示系统中每种类型的元信息。
例如,您的应用程序已加载员工信息。之后,您可以确定加载的数据中显示哪种元类型,并可以强制创建适当的子屏幕。最后一部分工作是将适当的数据传递到每个子屏幕。
这是非常模糊的解释,抱歉我的英语,如果您对我的解释有任何疑问,请随时再次提问
I think the best in your case would be to devide all possible data in the system by data classes - metatypes. after that, in xml, specify data metatype so your data would be always have metatype. And when, before view creation, you should read all metatypes for data you are intend to display and create screen controls according to that metatypes. After that you could load and display data. Such approach works well in my small programm and I thinks it would yield good results in your system too.
[EDIT]
OK, your application includes business domain (your business data, business logic and rules for data displaying). All this things you have spread among three parts: Model, View and ViewModel. As I understand correctly your question is stright about ViewModel.
For example your hypothetical application containы employee information and suppose every employee may have three types of information about he or she:
So we have domain - employee. This domain may be devided into three metatype:
For each metatype we should create subscreen which would display metatype information according to business rules. I'll recomend you to make metatype subscreens with MVC pattern because of in case of editing of data some special editing rule or data validation may be applyed. When we have each subscreen created we can be free to display each type of meta information in the system.
For example you application have loaded employee information. After that you can determine which metatype presented in loaded data and can force creation of appropriate subscreens. The last part of work is to pass appropriate data to each sub screen.
It was very vague explanation sorry for my english, if you have any question about I have explained feel free and ask question again