在 .NET 中使用 DSL 创建动态 UI
我正在为客户开发 WPF 应用程序。应用程序需要在生产运行开始时提示用户填充多个字段。提示用户输入的数据取决于与生产运行相关的产品类型。例如,产品 A 可能要求用户输入有效期、批号,而产品 B 可能只要求用户输入生产日期。
我需要动态创建 UI 并显示字段名称、输入控件(文本框、列表框、复选框等)。
系统需要灵活,并且需要建立一种允许用户“创建”动态 UI 布局的机制。
我正在考虑各种选项,例如:
XML 来声明用户想要的 ui 结构。然后,应用程序将处理 XML 并为各种 XML 元素创建适当的 ui 控件
自定义 DSL,允许用户输入如下内容:
“为字段批号创建文本框”
与 xml 方法一样,应用程序将保存上述内容并将其分配给产品并将其保存在数据库中。在生产运行开始期间,应用程序动态创建 UI。
最初,用户将手动编辑这些文件并将它们分配给产品。最终,我们计划拥有一个图形前端,用于设计具有拖放支持的 UI。
我对 DSL 没有太多经验。只是想知道上述内容是否适合 DSL 应用程序,或者我是否应该采取完全不同的方法。
I'm developing a WPF application for a client. The application needs to prompt the user at the start of a production run to populate a number of fields. The data the user is prompted to enter is dependent on the type of product associated with the production run. So for example, Product A may require the user to enter an expiry number, lot number while Product B may require the user to enter a manufacturing date only.
I will need to dynamically create the UI and display the name of the field, the input control (text box, list box, checkbox etc) .
The system needs to be flexible and a mechanism to allow the user "create" the dynamic UI layout needs to be put in place.
I'm looking at various options, such as:
XML to declare the ui structure the user would like. The app would then process the XML and create apprropriate ui controls for the various XML elements
A custom DSL which would allow the user to enter something like:
"create textbox for field LOT NUMBER"
Like the xml approach, the app will save the above and assign it to a Product and save it in the DB. During the start of the production run the app dynamically creates the UI.
Initially the user will edit these files by hand and assign them to a product. Eventually we plan to have a graphical front end for designing the UI with drag and drop support.
I don't have much experience with DSLs. Just wondering if the above is a suitable application for DSLs or if I should take a completely different approach.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Microsoft 提供可视化和建模 SDK,以前称为 DSL工具包。
这包括用于创建 DSL 的图形设计器。设计器的输出是
例如,您将为特定产品类型创建 DSL 实例,这可能表明该产品类型需要输入零件号、颜色和有效期。保存模型实例时,它会自动为用户控件生成 .xaml 文件,其中包含零件编号的文本框、颜色的颜色选择器以及到期日期的日期选择器。
Microsoft offers the Visualization and Modeling SDK, formerly known as the DSL Toolkit.
This includes a graphical designer for creating your DSL. The output of the designer is
An example would be that you would create a DSL instance for a particular product type which might say that the product type requires the input of a part number, a color, and an expiration date. When you save the model instance, it would automatically generate your .xaml file for a user control containing a text box for the part number, a color picker for the color, and a date picker for the expiration date.