修正,其实只要在基础资料类中加入[XafDefaultProperty("名称")]标签即可。
namespace NEO.ERP.Module.BusinessObjects.Business { //引用显示名称 [XafDefaultProperty("名称")] public partial class 公共基础资料基类 { public 公共基础资料基类(Session session) : base(session) { } public override void AfterConstruction() { base.AfterConstruction(); } } }
下面的是老的引用方法。
在Module项目中如果手工增加的XPO Business Object类,增加了[XafDefaultProperty("名称")]属性后,该对象被别的类调用就可以显示一个下拉列表。
1 using System; 2 using System.Linq; 3 using System.Text; 4 using DevExpress.Xpo; 5 using DevExpress.ExpressApp; 6 using System.ComponentModel; 7 using DevExpress.ExpressApp.DC; 8 using DevExpress.Data.Filtering; 9 using DevExpress.Persistent.Base; 10 using System.Collections.Generic; 11 using DevExpress.ExpressApp.Model; 12 using DevExpress.Persistent.BaseImpl; 13 using DevExpress.Persistent.Validation; 14 15 namespace HelloXAF.Module.BusinessObjects 16 { 17 [DefaultClassOptions] 18 //[ImageName("BO_Contact")] 19 [XafDefaultProperty("名称")] 20 //[DefaultListViewOptions(MasterDetailMode.ListViewOnly, false, NewItemRowPosition.None)] 21 //[Persistent("DatabaseTableName")] 22 // Specify more UI options using a declarative approach (https://documentation.devexpress.com/#eXpressAppFramework/CustomDocument112701). 23 public class AAA : BaseObject 24 { // Inherit from a different class to provide a custom primary key, concurrency and deletion behavior, etc. (https://documentation.devexpress.com/eXpressAppFramework/CustomDocument113146.aspx). 25 public AAA(Session session) 26 : base(session) 27 { 28 } 29 public override void AfterConstruction() 30 { 31 base.AfterConstruction(); 32 // Place your initialization code here (https://documentation.devexpress.com/eXpressAppFramework/CustomDocument112834.aspx). 33 } 34 //private string _PersistentProperty; 35 //[XafDisplayName("My display name"), ToolTip("My hint message")] 36 //[ModelDefault("EditMask", "(000)-00"), Index(0), VisibleInListView(false)] 37 //[Persistent("DatabaseColumnName"), RuleRequiredField(DefaultContexts.Save)] 38 //public string PersistentProperty { 39 // get { return _PersistentProperty; } 40 // set { SetPropertyValue("PersistentProperty", ref _PersistentProperty, value); } 41 //} 42 43 //[Action(Caption = "My UI Action", ConfirmationMessage = "Are you sure?", ImageName = "Attention", AutoCommit = true)] 44 //public void ActionMethod() { 45 // // Trigger a custom business logic for the current record in the UI (https://documentation.devexpress.com/eXpressAppFramework/CustomDocument112619.aspx). 46 // this.PersistentProperty = "Paid"; 47 //} 48 49 public string 名称 { get; set; } 50 51 } 52 }
AAA 列表显示
汇率体系调用AAA时显示如下。
但是,当我们不是通过代码建BO对象时,而是通过ORMDataModel设计器来创建BO对象的时候。设计器创建的BO对象不是像手工建的BO像,设计器创建的对象不是派生于BaseObject,而是派生于XPObject。当我们给基础资料对象赋[XafDefaultProperty("Code")]属性的时候,发现引用该基础资料的下拉列表显示不出来Code或者Name。
网上搜索找到一篇文章。
https://www.devexpress.com/Support/Center/Question/Details/Q306912
原意是 Only the BaseObject class overrides the ToString method, to process the XafDefaultPropertyAttribute.
需要自己手工再处理Tostring()
找到需要被调用的基础资料类,
1 using System; 2 using DevExpress.Xpo; 3 using DevExpress.Data.Filtering; 4 using System.Collections.Generic; 5 using System.ComponentModel; 6 using DevExpress.Persistent.Base; 7 using DevExpress.ExpressApp.DC; 8 using DevExpress.ExpressApp; 9 10 namespace HelloXAF.Module.BusinessObjects.ORMDataModel_Base 11 { 12 [DefaultClassOptions] 13 [XafDefaultProperty("编码")] 14 public partial class 币别 15 { 16 public 币别(Session session) : base(session) { } 17 public override void AfterConstruction() { base.AfterConstruction(); } 18 19 public override string ToString() 20 { 21 22 //if (!isDefaultPropertyAttributeInit) 23 //{ 24 string defaultPropertyName = string.Empty; 25 XafDefaultPropertyAttribute xafDefaultPropertyAttribute = XafTypesInfo.Instance.FindTypeInfo(GetType()).FindAttribute<XafDefaultPropertyAttribute>(); 26 if (xafDefaultPropertyAttribute != null) 27 { 28 defaultPropertyName = xafDefaultPropertyAttribute.Name; 29 } 30 else 31 { 32 DefaultPropertyAttribute defaultPropertyAttribute = XafTypesInfo.Instance.FindTypeInfo(GetType()).FindAttribute<DefaultPropertyAttribute>(); 33 if (defaultPropertyAttribute != null) 34 { 35 defaultPropertyName = defaultPropertyAttribute.Name; 36 } 37 } 38 if (!string.IsNullOrEmpty(defaultPropertyName)) 39 { 40 var defaultPropertyMemberInfo = ClassInfo.FindMember(defaultPropertyName); 41 object obj = defaultPropertyMemberInfo.GetValue(this); 42 if (obj != null) 43 { 44 return obj.ToString(); 45 } 46 } 47 //isDefaultPropertyAttributeInit = true; 48 //} 49 //if (defaultPropertyMemberInfo != null) 50 //{ 51 // object obj = defaultPropertyMemberInfo.GetValue(this); 52 // if (obj != null) 53 // { 54 // return obj.ToString(); 55 // } 56 //} 57 return base.ToString(); 58 } 59 } 60 61 }
这样,设计器添加的基础资料也能显示出来了。