Search code examples
entity-frameworkdevexpressxaf

specify a property editor inside the business object


I am using Dev Express XAF with Entity framework. I want to be able to specify that my Description field uses property editor DevExpress.ExpressApp.HtmlPropertyEditor.Win.HtmlPropertyEditor

I can do this by setting the property editor inside model.xafml in the views that involve the field. However I would prefer to just set it once in the business object as an attribute.

Is there a way to do this?


Solution

  • The DevExpress knowledge base explains how to achieve this here: KA18907. See section 2.2 and 2.3.

    If your business object is declared in the same module as the editor, then you can do this:

    //Class declared in a WinForms module, for example
    public class BusinessObject : BaseObject {
        ...
        [ModelDefault("PropertyEditorType", "SampleSolution.Module.Win.PropertyEditors.CustomStringEditor")]
        public string Description {
            get { return GetPropertyValue<string>("Description"); }
            set { SetPropertyValue<string>("Description", value); }
        }
    }
    

    Otherwise, use the EditorAlias attribute instead.

    public class BusinessObject : BaseObject {
        ...
        [EditorAlias("CustomStringEdit")]
        public string Description {
            get { return GetPropertyValue<string>("Description"); }
            set { SetPropertyValue<string>("Description", value); }
        }
    }
    

    and set the same string identifier in your editor. (This allows different editors to be specified separate Web and Win modules).

    [PropertyEditor(typeof(String), "CustomStringEdit", false)]
    public class CustomStringEditor : StringPropertyEditor {
        public CustomStringEditor(Type objectType, IModelMemberViewItem info)
            : base(objectType, info) {  }
        ...
    }