Devexpress xaf ungroup layout of inherited class. (programmaticaly)

孤者浪人 提交于 2019-12-06 21:18:29

Sure you can do it via code. Here is the DevExpress documentation: Extend and Customize the Application Model in Code.

You need to provide your own ModelNodesGeneratorUpdater for the detail views part of the XAF model. It should look something like this:

public class MyDetailViewGeneratorUpdater : ModelNodesGeneratorUpdater<ModelDetailViewLayoutNodesGenerator> 
{
    public override void UpdateNode(ModelNode node) 
    {
        IModelDetailViewLayout layout = node as IModelDetailViewLayout;
        IModelDetailView detailView = (IModelDetailView)layout.Parent;
        if (!XafTypesInfo.Instance.FindTypeInfo(typeof(MyBase)).IsAssignableFrom(detailView.ModelClass.TypeInfo))   return;
        foreach (IModelDetailViewLayoutElement element in layout)
            UpdateLayoutItems(element, detailView.Items, XafTypesInfo.Instance.FindTypeInfo(typeof(MyBase)).FindMember("Description"));
    }

    private void UpdateLayoutItems(IModelDetailViewLayoutElement element, IModelDetailViewItems items, IMemberInfo member) {
        IModelLayoutItem item = element as IModelLayoutItem;
        IModelLayoutGroup group = element as IModelLayoutGroup;
        if(group != null){
            foreach(IModelDetailViewLayoutElement element1 in group)
            UpdateLayoutItems(element1, items, member);
        }
        else if (item != null) {
            RemoveFromGroup(item); // you just need to code this bit of magic
        }
    }
}

Don't forget to register your updater in the module:

public override void AddGeneratorUpdaters(ModelNodesGeneratorUpdaters updaters)
{
    base.AddGeneratorUpdaters(updaters);
    updaters.Add(new MyDetailViewGeneratorUpdater());
}

I'm afraid there are no built-in attributes for this, but here are some directions:

First, be sure to read oficial DevExpress recomendations about Layout Customization.

Second, check Xpand framework's partial view inheritance. Surely a powerful tool, but will not necessarly save you time in the case you described above, but since I don't know all the complexity you've got, here's a player you can count in.

Also, have you considered giving the grouped layout a chance? You can find ways to make it attractive and useful. Check how to make it expandable: https://www.devexpress.com/Support/Center/Question/Details/Q101774

In case none of the solutions above meets your needs and all you need is to save time ungrouping it in all views, keep in mind you can edit xaf's model XML file directly. LayoutGroups generated after the parent object properties have the same ID across all views, and you can smartly set ShowCaption to false in those groups for all views ;).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!