自定义控件开发4--同一集合中添加不同类型的Item条目,例如ButtonComman,LinkButtonCommand.

在我们前面完成了点击'Add' 按钮添加默认的Item 后,这里我们可以有选择的添加多个Item,

我觉得最关键步骤就是实现Collection<BaseItem>,自定义CollectionEditor类来格式化Editor界面.

 

   public class MyCollectionEditor : CollectionEditor
    {
        
public MyCollectionEditor(Type type)
            : 
base(type)
        { }
        
protected override bool CanSelectMultipleInstances()
        {
            
return true;
        }
        
protected override Type[] CreateNewItemTypes()
        {
            
return new Type[] { typeof(MyFirstItem), typeof(MySecondItem) };
        }
        
protected override object CreateInstance(Type itemType)
        {
            
if (itemType == typeof(MyFirstItem))
            {
                
return new MyFirstItem();
            } 
if (itemType == typeof(MySecondItem))
            {
                
return new MySecondItem();
            } 
return null;
        }
    }

 

DownLoad

posted on 2009-11-24 18:27  博览潇湘  阅读(467)  评论(0)    收藏  举报

导航