扩展XAF模型信息实现自定义功能
如何隐藏 web listview 的 编辑控制列如下图: 这列怎么让它隐藏?
感谢【少侠】XAF_杨东 提供解答!感谢XAF_小学生整理。
A: 注册自定义接口IModelListViewExtender 增加控制项 .
1、定义一个IModelListViewExtender接口。
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ExpressApp.Extensions.Common { public interface IModelWebListViewExtender { bool HiddenCommandColumn { get; set; } } }
2、到XAF的web工程中注册这个扩展。
using System; using System.Linq; using System.Text; using System.ComponentModel; using DevExpress.ExpressApp; using DevExpress.ExpressApp.DC; using System.Collections.Generic; using DevExpress.ExpressApp.Model; using DevExpress.ExpressApp.Editors; using DevExpress.ExpressApp.Actions; using DevExpress.ExpressApp.Updating; using DevExpress.ExpressApp.Model.Core; using DevExpress.ExpressApp.Model.DomainLogics; using DevExpress.ExpressApp.Model.NodeGenerators; using DevExpress.Persistent.BaseImpl; using ExpressApp.Extensions.Common; namespace 资产管理.Module.Web { [ToolboxItemFilter("Xaf.Platform.Web")] // For more typical usage scenarios, be sure to check out https://documentation.devexpress.com/eXpressAppFramework/clsDevExpressExpressAppModuleBasetopic.aspx. public sealed partial class 资产管理AspNetModule : ModuleBase { private void Application_CreateCustomModelDifferenceStore(Object sender, CreateCustomModelDifferenceStoreEventArgs e) { #if !DEBUG e.Store = new ModelDifferenceDbStore((XafApplication)sender, typeof(ModelDifference), true, "Web"); e.Handled = true; #endif } private void Application_CreateCustomUserModelDifferenceStore(Object sender, CreateCustomModelDifferenceStoreEventArgs e) { e.Store = new ModelDifferenceDbStore((XafApplication)sender, typeof(ModelDifference), false, "Web"); e.Handled = true; } public 资产管理AspNetModule() { InitializeComponent(); } public override IEnumerable<ModuleUpdater> GetModuleUpdaters(IObjectSpace objectSpace, Version versionFromDB) { return ModuleUpdater.EmptyModuleUpdaters; } public override void Setup(XafApplication application) { base.Setup(application); application.CreateCustomModelDifferenceStore += Application_CreateCustomModelDifferenceStore; application.CreateCustomUserModelDifferenceStore += Application_CreateCustomUserModelDifferenceStore; // Manage various aspects of the application UI and behavior at the module level. } //增加这个方法: public override void ExtendModelInterfaces(ModelInterfaceExtenders extenders) { extenders.Add<IModelListView, IModelWebListViewExtender>(); base.ExtendModelInterfaces(extenders); } } }
3、打开web的xafml,配置
4、写一个Controller来处理这些配置项目
GridViewCommandColumn 即选择操作的列
using System; using DevExpress.ExpressApp; using DevExpress.ExpressApp.Web.Editors.ASPx; using DevExpress.Web; namespace ExpressApp.Extensions.Common.Web.Controllers { public partial class ListViewExtenderController : ViewController { public ListViewExtenderController() { InitializeComponent(); RegisterActions(components); TargetViewType = ViewType.ListView; } protected override void OnDeactivated() { ListView view = (ListView)View; if (view.Editor == null || !(view.Editor is ASPxGridListEditor) || ((ASPxGridListEditor)view.Editor).Control == null || !(((ASPxGridListEditor)view.Editor).Control is ASPxGridView) || view.Model == null || !(view.Model is IModelWebListViewExtender)) return; ASPxGridView gridView = (ASPxGridView)view.Editor.Control; gridView.Load -= AdjustGridView; base.OnDeactivated(); } void AdjustGridView(object sender, EventArgs e) { ListView view = (ListView)View; if (view.Editor == null || !(view.Editor is ASPxGridListEditor) || ((ASPxGridListEditor)view.Editor).Control == null || !(((ASPxGridListEditor)view.Editor).Control is ASPxGridView) || view.Model == null || !(view.Model is IModelWebListViewExtender)) return; ASPxGridView gridView = (ASPxGridView)view.Editor.Control; IModelWebListViewExtender viewExtender = (IModelWebListViewExtender)view.Model; foreach (GridViewColumn c in gridView.Columns) { if (c is GridViewCommandColumn) { c.Visible = !viewExtender.HiddenCommandColumn; } } } protected override void OnViewControlsCreated() { base.OnViewControlsCreated(); ListView view = (ListView)View; if (view.Editor == null || !(view.Editor is ASPxGridListEditor) || ((ASPxGridListEditor)view.Editor).Control == null || !(((ASPxGridListEditor)view.Editor).Control is ASPxGridView) || view.Model == null || !(view.Model is IModelWebListViewExtender)) return; ASPxGridView gridView = (ASPxGridView)view.Editor.Control; gridView.Load += AdjustGridView; } } }
完成
XAF开发成品案例参考
如果您觉得阅读本文对您有帮助,请点一下“推荐”按钮,您的“推荐”将是我最大的写作动力!欢迎各位转载,但是未经作者本人同意,转载文章之后必须在文章页面明显位置给出作者和原文连接,否则保留追究法律责任的权利。
作者博客: http://www.cnblogs.com/foreachlife
欢迎加入CIIP框架\XAF技术应用交流群: 336090194 群文件中有更多相关工具及文档资料
转载请注明出处。多谢!
欢迎加我微信: admiralcn 或扫码: