How to: Detect a Lookup List View in Code 如何:在代码中检测查找列表视图
This topic demonstrates how to check if the current View is a Lookup List View. This can be useful if you want to customize Lookups only, for instance, to hide the New Action displayed below the Lookup List View.
本主题演示如何检查当前视图是否为查找列表视图。如果只想自定义"查找"(例如,以隐藏"查找列表"视图下方显示的"新建操作"),则此功能非常有用。
Note 注意
Mobile applications do not have a specific template for Lookup List Views and do not support the approach described in this topic.
移动应用程序没有用于查找列表视图的特定模板,并且不支持本主题中描述的方法。
Implement a View Controller that targets List Views only and override the OnActivated method. Check that the Frame.Context value is LookupControl or LookupWindow. If the condition is true, this means that the current List View is a Lookup List View.
实现仅面向列表视图的视图控制器并覆盖 On"已激活"方法。检查 Frame.上下文值是查找控制还是查找窗口。如果条件为 true,则表示当前列表视图是"查找列表视图"。
You can now, for example, deactivate the New Action in all Lookups. Use the Frame.GetController<ControllerType> method to get the NewObjectViewController and then use the NewObjectViewController.NewObjectAction property to access the New Action.
例如,您现在可以在所有查找中停用"新操作"。使用 Frame.GetController<ControllerType> 方法获取 NewObjectView 控制器,然后使用 NewObjectView 控制器.NewObjectAction 属性访问"新建操作"。
using DevExpress.ExpressApp; using DevExpress.ExpressApp.SystemModule; // ... public class DeactivateNewActionInLookupsController : ViewController<ListView> { protected override void OnActivated() { base.OnActivated(); if (Frame.Context == TemplateContext.LookupControl || Frame.Context == TemplateContext.LookupWindow) { NewObjectViewController controller = Frame.GetController<NewObjectViewController>(); if (controller != null) { controller.NewObjectAction.Active.SetItemValue("LookupListView", false); } } } }
Run a WinForms or ASP.NET application to ensure that the New Action is deactivated in all Lookup List Views.
运行 WinForms 或ASP.NET应用程序,以确保在所有查找列表视图中停用"新操作"。
You can also detect a Lookup List View by its View.Id: all Lookup List Views have identifiers with the "_LookupListView" suffix by default. However, this also detects Views that were initially designed as Lookups, but are not used as Lookups.
您还可以按其View.Id检测查找列表视图:默认情况下,所有查找列表视图都有带有"_LookupListView"后缀的标识符。但是,这还会检测最初设计为查找但未用作查找的视图。
Tip 提示
If you want to hide the New Action for a particular Lookup List View, find the corresponding View node in the Model Editor and set the IModelView.AllowNew property to false.
如果要隐藏特定查找列表视图的"新建操作",请在模型编辑器中查找相应的视图节点,并将 IModelView.AllowNew 属性设置为 false。
XAF开发成品案例参考
如果您觉得阅读本文对您有帮助,请点一下“推荐”按钮,您的“推荐”将是我最大的写作动力!欢迎各位转载,但是未经作者本人同意,转载文章之后必须在文章页面明显位置给出作者和原文连接,否则保留追究法律责任的权利。
作者博客: http://www.cnblogs.com/foreachlife
欢迎加入CIIP框架\XAF技术应用交流群: 336090194 群文件中有更多相关工具及文档资料
转载请注明出处。多谢!
欢迎加我微信: admiralcn 或扫码:
![](http://files.cnblogs.com/files/foreachlife/wx.bmp)