How to: Apply Application Model Changes to the Current View Immediately 如何:立即将应用程序模型更改应用于当前视图
This topic describes how to implement Actions that make changes in the Application Model and then apply these changes to the current View without recreating it.
本主题介绍如何在应用程序模型中实现更改的操作,然后将这些更改应用于当前视图而不重新创建它。
Note 注意
This solution does not apply to Mobile applications, because they do not support UI customization without recompilation.
此解决方案不适用于移动应用程序,因为它们不支持 UI 自定义,而不重新编译。
In the Action's SimpleAction.Execute event handler, save the Frame's View (Frame.View) object to a variable, and call the Frame.SetView method to detach the View from Frame. Pass null (Nothing in VB) as the view argument, and false as the disposeOldView argument to keep the detached view operational. After that, make changes to the Application model and call the View.LoadModel method with the false parameter. Next, use the SetView method's SetView(View view) overload to reattach the updated View to the Frame. The Controller below implements two Actions (SwitchMasterDetailMode and SwitchEditor) that illustrate this pattern.
在操作的"简单操作.执行事件"处理程序中,将帧视图(Frame.View)对象保存到变量,然后调用 Frame.SetView 方法将视图从帧中分离出来。将 null(VB 中没有)作为视图参数,将 false 作为 disposeOldView 参数,以保持分离视图正常运行。之后,对应用程序模型进行更改,并调用 View.LoadModel 方法,方法是使用 false 参数。接下来,使用 SetView 方法的 SetView(视图视图)重载将更新的视图重新附加到框架。下面的控制器实现两个操作(切换主细节模式和切换编辑器),以说明此模式。
using System; using DevExpress.ExpressApp; using DevExpress.ExpressApp.Actions; using DevExpress.ExpressApp.Scheduler.Win; using DevExpress.ExpressApp.Win.Editors; using DevExpress.Persistent.Base; using DevExpress.Persistent.Base.General; // ... public class RefreshViewControlsAfterModelChangesViewController : ObjectViewController<ListView, IEvent> { public RefreshViewControlsAfterModelChangesViewController() { new SimpleAction(this, "SwitchMasterDetailMode", PredefinedCategory.View.ToString(), (s, e) => { // Save the current View. ListView savedView = (ListView)Frame.View; // Detach the View from the Frame without disposing of it. if(Frame.SetView(null, true, null, false)) { // Make required changes to the related Application Model nodes. MasterDetailMode defaultMasterDetailMode = MasterDetailMode.ListViewOnly; savedView.Model.MasterDetailMode = savedView.Model.MasterDetailMode == defaultMasterDetailMode ? MasterDetailMode.ListViewAndDetailView : defaultMasterDetailMode; // Update the saved View according to the latest model changes and assign it back to the current Frame. savedView.LoadModel(false); Frame.SetView(savedView); } }); new SimpleAction(this, "SwitchEditor", PredefinedCategory.View.ToString(), (s, e) => { var savedView = View; if(Frame.SetView(null, true, null, false)) { Type defaultListEditorType = Application.Model.Views.DefaultListEditor; savedView.Model.EditorType = savedView.Model.EditorType == defaultListEditorType ? typeof(SchedulerListEditor) : defaultListEditorType; savedView.LoadModel(false); Frame.SetView(savedView); } }); } }
XAF开发成品案例参考
如果您觉得阅读本文对您有帮助,请点一下“推荐”按钮,您的“推荐”将是我最大的写作动力!欢迎各位转载,但是未经作者本人同意,转载文章之后必须在文章页面明显位置给出作者和原文连接,否则保留追究法律责任的权利。
作者博客: http://www.cnblogs.com/foreachlife
欢迎加入CIIP框架\XAF技术应用交流群: 336090194 群文件中有更多相关工具及文档资料
转载请注明出处。多谢!
欢迎加我微信: admiralcn 或扫码:

【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· 周边上新:园子的第一款马克杯温暖上架
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?
· 使用C#创建一个MCP客户端