简体   繁体   English

你如何实现复杂的 UI 逻辑?

[英]How do you implement sophisticated UI logic?

I'm looking for best practices for sophisticated UI logic implementation.我正在寻找复杂的 UI 逻辑实现的最佳实践。 I'm working on a Windows Forms application, but I believe there should be generic patterns for solving this problem on any platform.我正在开发一个 Windows Forms 应用程序,但我相信在任何平台上都应该有解决这个问题的通用模式。

I have a number of controls on my form, there are lists, buttons, tables and a tree view.我的表单上有许多控件,有列表、按钮、表格和树视图。 So, the idea is that depending on "context" some of the controls are enabled, while others are disabled.因此,想法是根据“上下文”启用某些控件,而禁用其他控件。 Some of them can provide some features for the moment and others don't.其中一些可以暂时提供一些功能,而另一些则不能。

Currently it's implemented "as is".目前它是“按原样”实施的。 I handle events, check for changes (new tree node selected, couple of nodes selected, etc.) and then decide whether some of the controls need to be disabled or enabled.我处理事件,检查更改(选择了新的树节点,选择了几个节点等),然后决定是否需要禁用或启用某些控件。 I don't really like this approach because the Form code looks to complicated.我不太喜欢这种方法,因为表单代码看起来很复杂。 And if I need to add more logic, it becomes even more complicated.如果我需要添加更多逻辑,它会变得更加复杂。 I'm really concerned, since we're quite agile and new features or lots of changes are the daily norm.我真的很担心,因为我们非常敏捷,新功能或大量更改是日常常态。

I'm thining of separating all this logic into parts (Features), where each feature is an object that know how to check its state, and depending on this state, enable or disable the related controls.我想将所有这些逻辑分成几部分(功能),其中每个功能都是一个 object,它知道如何检查其 state,并根据此 state,启用或禁用相关控件。

Don't really want to invent anything new and trying to find any good ideas that are widely used.不要真的想发明任何新东西并试图找到任何被广泛使用的好主意。 Please, don't recommend single UpdateUI() method approach, I believe that won't change anything in the long term.请不要推荐单一的 UpdateUI() 方法,我相信从长远来看这不会改变任何事情。

Thanks.谢谢。

This blog series may be what you are looking for:这个博客系列可能是您正在寻找的:

http://codebetter.com/jeremymiller/2007/07/26/the-build-your-own-cab-series-table-of-contents/ http://codebetter.com/jeremymiller/2007/07/26/the-build-your-own-cab-series-table-of-contents/

(may look like a lot of material, but start just with the "Humble Dialog box", based on Michael Feathers great article ). (可能看起来有很多材料,但从“Humble Dialog box”开始,基于Michael Feathers 的精彩文章)。 This is all about "how to separate your logic from your UI code", which may solve most of your problems.这就是“如何将你的逻辑与你的 UI 代码分开”,这可能会解决你的大部分问题。

User interface data binding and encapsulating your business logic into business objects is the way to go.用户界面数据绑定并将您的业务逻辑封装到业务对象中是 go 的方式。 CSLA.NET framework by Rocky Lhotka has a lot of great features built-in as well as a number of sample applications. Rocky Lhotka 的 CSLA.NET 框架内置了许多出色的功能以及许多示例应用程序。 I've used it in a medium-size WPF project and a huge WinForms/CAB application and really enjoyed it.我已经在一个中型 WPF 项目和一个巨大的 WinForms/CAB 应用程序中使用它,并且非常喜欢它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM