在业务对象内指定 属性 编辑器
specify a property editor inside the business object
我正在使用 Dev Express
XAF
和 Entity framework
。
我希望能够指定我的 Description
字段使用 属性 编辑器 DevExpress.ExpressApp.HtmlPropertyEditor.Win.HtmlPropertyEditor
我可以通过在涉及该字段的视图中的 model.xafml
内设置 属性 编辑器来做到这一点。但是我更愿意只在 business
对象中将它设置一次作为属性。
有办法吗?
DevExpress 知识库在此处解释了如何实现这一点:KA18907。请参阅第 2.2 和 2.3 节。
如果您的业务对象是在与编辑器相同的模块中声明的,那么您可以这样做:
//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); }
}
}
否则,请改用 EditorAlias
属性。
public class BusinessObject : BaseObject {
...
[EditorAlias("CustomStringEdit")]
public string Description {
get { return GetPropertyValue<string>("Description"); }
set { SetPropertyValue<string>("Description", value); }
}
}
并在您的编辑器中设置相同的字符串标识符。 (这允许不同的编辑器指定单独的Web和Win模块)。
[PropertyEditor(typeof(String), "CustomStringEdit", false)]
public class CustomStringEditor : StringPropertyEditor {
public CustomStringEditor(Type objectType, IModelMemberViewItem info)
: base(objectType, info) { }
...
}
我正在使用 Dev Express
XAF
和 Entity framework
。
我希望能够指定我的 Description
字段使用 属性 编辑器 DevExpress.ExpressApp.HtmlPropertyEditor.Win.HtmlPropertyEditor
我可以通过在涉及该字段的视图中的 model.xafml
内设置 属性 编辑器来做到这一点。但是我更愿意只在 business
对象中将它设置一次作为属性。
有办法吗?
DevExpress 知识库在此处解释了如何实现这一点:KA18907。请参阅第 2.2 和 2.3 节。
如果您的业务对象是在与编辑器相同的模块中声明的,那么您可以这样做:
//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); }
}
}
否则,请改用 EditorAlias
属性。
public class BusinessObject : BaseObject {
...
[EditorAlias("CustomStringEdit")]
public string Description {
get { return GetPropertyValue<string>("Description"); }
set { SetPropertyValue<string>("Description", value); }
}
}
并在您的编辑器中设置相同的字符串标识符。 (这允许不同的编辑器指定单独的Web和Win模块)。
[PropertyEditor(typeof(String), "CustomStringEdit", false)]
public class CustomStringEditor : StringPropertyEditor {
public CustomStringEditor(Type objectType, IModelMemberViewItem info)
: base(objectType, info) { }
...
}