XAF 如何用下拉复选编辑枚举属性

http://www.devexpress.com/Support/Center/e/E689.aspx

 
using System;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.ExpressApp.Utils;
using DevExpress.ExpressApp.Model;
using DevExpress.ExpressApp.Editors;
using DevExpress.XtraEditors.Repository;

namespace WinSolution.Module.Win {
    [PropertyEditor(
typeof(System.Enum), true)]
    
public class EnumPropertyEditorEx : DevExpress.ExpressApp.Win.Editors.EnumPropertyEditor {
        
public EnumPropertyEditorEx(Type objectType, IModelMemberViewItem model)
            : 
base(objectType, model) {
        }
        
private bool TypeHasFlagsAttribute() {
            
return GetUnderlyingType().GetCustomAttributes(typeof(FlagsAttribute), true).Length > 0;
        }
        
protected override object CreateControlCore() {
            CheckedComboBoxEdit checkedEdit 
= new CheckedComboBoxEdit();
            checkedEdit.TextChanged 
+= checkedEdit_TextChanged;
            
if (TypeHasFlagsAttribute())
                
return checkedEdit;
            
return base.CreateControlCore();
        }
        
//Dennis: this code is needed to bypass a binding problem in the XtraEditors (S35490)
        private void checkedEdit_TextChanged(object sender, EventArgs e) {
            ((CheckedComboBoxEdit)sender).RefreshEditValue();
        }
        
protected override RepositoryItem CreateRepositoryItem() {
            
if (TypeHasFlagsAttribute())
                
return new RepositoryItemCheckedComboBoxEdit();
            
return base.CreateRepositoryItem();
        }
        
protected override void SetupRepositoryItem(RepositoryItem item) {
            
base.SetupRepositoryItem(item);
            
if (TypeHasFlagsAttribute()) {
                EnumDescriptor descriptor 
= new EnumDescriptor(GetUnderlyingType());
                RepositoryItemCheckedComboBoxEdit checkedItem 
= ((RepositoryItemCheckedComboBoxEdit)item);
                checkedItem.BeginUpdate();
                checkedItem.Items.Clear();
                checkedItem.SelectAllItemVisible 
= false;
                
//Dennis: this is required to show localized items in the editor.
                foreach (object value in descriptor.Values)
                    checkedItem.Items.Add(value, descriptor.GetCaption(value), CheckState.Unchecked, 
true);
                
//Dennis: use this method if you don't to show localized items in the editor.
                
//checkedItem.SetFlags(GetUnderlyingType());
                checkedItem.EndUpdate();
            }
        }
    }
}

欢迎转载,转载请注明出处:http://www.cnblogs.com/Tonyyang/

原文地址:https://www.cnblogs.com/Tonyyang/p/1802195.html