基于 XML 的元数据驱动的 WPF 应用程序

发布于 2024-11-02 19:13:39 字数 476 浏览 1 评论 0原文

我正在 WPF 中开发 BI 应用程序。我正在设计其架构,并正在寻找一种将视图中的控件直接绑定到包含视图元数据的 xml 的方法。你认为这可能吗?那怎么办?或者是否建议从 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
Screenshot of a dashboard we currently load from xml, through a normal read write operation

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 技术交流群。

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

发布评论

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

评论(3

人事已非 2024-11-09 19:13:39

我不确定我是否完全理解你想要做什么。如果您只想将一些 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.

長街聽風 2024-11-09 19:13:39

我建议使用 XAML 而不是 XML。

XAML 不仅允许您定义 UI,而且 XAML 还可以包含其他元数据或配置信息,您可以以 XAML 的形式直接读取/写入 CLR 类。

是,

  1. Xaml 序列化与 Xml 的序列化完全相同,
  2. Xaml 将为您在 Visual Studio 中编辑时提供强大的智能感知(xml 也可以提供,但每次更改配置架构时都必须创建和更新架构)
  3. 好处 intellisense,Xaml 更好,因为它会自动给出验证错误
  4. 它还允许您使用枚举
  5. 它还将隐藏/显示基于继承层次结构的成员或类
  6. 您也可以从来自数据库的字符串加载 XAML
  7. 它如果您的对象是从 DependencyObject 派生的,那么您也可以指定绑定,并且您将能够在 UI 中传输或重用绑定。

例如,

public class ScreenElement{
    public string Author {get;set;}
    public DateTime DateCreated {get;set;}
}

// XAML can not directly deal with generics so this step is
// necessary
public class ScreenElements : ObservableCollection<ScreenElement>
{
}

[ContentProperty("Elements")]
public class Screen
{
    public Screen(){
        this.Elements = new ScreenElements();
    }
    public string Title{get;set;}
    public bool ToolbarPresent {get;set;}

    // this attribute is necessary if 
    // you want to save Screen to xaml
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
    public ScreenElements Elements {get; private set;}
}

您的 Screen xaml 看起来像

<Screen xmlns="clr-namespace:MyNamespace"
        Title="Home Screen"
        ToolbarPresent="false"
        >
    <ScreenElement Author="Myself" DateCreated="..."/>
    <ScreenElement Author="Yourself" DateCreated="..."/>
</Screen>

您可以创建 XAML 资源并加载它,就像...

Screen s = XamlReader.Load(.. resource uri to your XAML)
// and now you can use your "s" loaded with elements to 
// populate your UI

foreach(ScreenElement e in s.Elements){
    // use attributes of e to populate things..
}

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,

  1. Xaml serialization is exactly same as that of Xml's serialization
  2. Xaml will give you powerful intellisense while editing in Visual Studio (xml also can give but you will have to create and update schema everytime you make changes to your configuration schema)
  3. In case of intellisense, Xaml is better because it will automatically give validation errors
  4. It will also allow you to use Enums
  5. It will also hide/show members or classes based on inheritance hierarchy
  6. You can load XAML from string coming from database as well
  7. It will let you specify bindings as well if your object is derived from DependencyObject and you will be able to transfer or reuse the bindings in your UI

For example,

public class ScreenElement{
    public string Author {get;set;}
    public DateTime DateCreated {get;set;}
}

// XAML can not directly deal with generics so this step is
// necessary
public class ScreenElements : ObservableCollection<ScreenElement>
{
}

[ContentProperty("Elements")]
public class Screen
{
    public Screen(){
        this.Elements = new ScreenElements();
    }
    public string Title{get;set;}
    public bool ToolbarPresent {get;set;}

    // this attribute is necessary if 
    // you want to save Screen to xaml
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
    public ScreenElements Elements {get; private set;}
}

And your Screen xaml can look like

<Screen xmlns="clr-namespace:MyNamespace"
        Title="Home Screen"
        ToolbarPresent="false"
        >
    <ScreenElement Author="Myself" DateCreated="..."/>
    <ScreenElement Author="Yourself" DateCreated="..."/>
</Screen>

You can create XAML resource and load it like...

Screen s = XamlReader.Load(.. resource uri to your XAML)
// and now you can use your "s" loaded with elements to 
// populate your UI

foreach(ScreenElement e in s.Elements){
    // use attributes of e to populate things..
}
相思碎 2024-11-09 19:13:39

我认为在您的情况下最好的方法是按数据类(元类型)划分系统中所有可能的数据。之后,在 xml 中指定数据元类型,以便您的数据始终具有元类型。在创建视图之前,您应该读取要显示的数据的所有元类型,并根据该元类型创建屏幕控件。之后您可以加载并显示数据。这种方法在我的小程序中效果很好,我认为它也会在您的系统中产生良好的结果。

[编辑]
好的,您的应用程序包括业务域(您的业务数据、业务逻辑和数据显示规则)。所有这些东西都分布在三个部分中:模型、视图和视图模型。据我正确理解,您的问题是关于 ViewModel 的。
例如,您假设的应用程序包含员工信息,并假设每个员工可能拥有三类有关他或她的信息:

  1. 个人信息(姓名、出生日期、照片、家庭住址、手机号码)
  2. 教育信息(有关教育的信息、工作经历列表)完成的培训课程)
  3. 专业经验信息(成功完成的商业项目列表)

所以我们有域 - 员工。该域可以分为三个元类型:

  1. 个人元类型
  2. 教育元类型
  3. 专业经验元类型

对于每个元类型,我们应该创建子屏幕,该子屏幕将根据业务规则显示元类型信息。我会建议您使用 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:

  1. Personal information (Name, date of birth, photo, home address, mobile phone number)
  2. Education information (information about education, list of completed training cources)
  3. Proffesional experience information (list of succesfully completed commercial projects)

So we have domain - employee. This domain may be devided into three metatype:

  1. Personal metatype
  2. Education metatype
  3. Proffesional experience 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

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