0

将VS2010(或VS2008中的智能标签)添加到我的控件中会导致VS崩溃。Visual Studio中的智能标签(又名ActionList)崩溃

下设计者用于动作列表:

internal class DataEditorDesigner : ComponentDesigner { 
[...] 
    public override DesignerActionListCollection ActionLists { 
     get { 
      var lists = new DesignerActionListCollection(); 
      lists.AddRange(base.ActionLists); 
      lists.Add(new DataEditorActionList(Component)); 
      return lists; 
     } 
    } 
} 

internal class DataEditorActionList : DesignerActionList { 
    public DataEditorActionList(IComponent component) : base(component) {} 
    public override DesignerActionItemCollection GetSortedActionItems() { 
     var items = new DesignerActionItemCollection(); 
     items.Add(new DesignerActionPropertyItem("DataSource", "Data Source:", "Data")); 
     items.Add(new DesignerActionMethodItem(this, "AddControl", "Add column...")); 
     return items; 
    } 
    private void AddControl() { 
     System.Windows.Forms.MessageBox.Show("dpa"); 
    } 
} 

DataSource属性被宣布为:

[AttributeProvider(typeof (IListSource))] 
    [DefaultValue(null)] 
    public object DataSource { 
[...] 

如何调试它的任何想法?

+0

智能标签听起来不太聪明 – 2010-06-30 22:05:40

+0

您可能想要将此问题提交给http://connect.microsoft.com/上的Microsoft Connect。也许这个问题已经知道了,也许它有一个解决方法。 – 2010-07-01 08:49:45

回答

0

我找到了解决方案。有必要向DesignerActionList类中添加包装器属性,这就是它们从中读取的位置,而不是实际的组件。此外,有必要写这样的代码:

internal static PropertyDescriptor GetPropertyDescriptor(IComponent component, string propertyName) { 
    return TypeDescriptor.GetProperties(component)[propertyName]; 
} 

internal static IDesignerHost GetDesignerHost(IComponent component) { 
    return (IDesignerHost) component.Site.GetService(typeof (IDesignerHost)); 
} 

internal static IComponentChangeService GetChangeService(IComponent component) { 
    return (IComponentChangeService) component.Site.GetService(typeof (IComponentChangeService)); 
} 

internal static void SetValue(IComponent component, string propertyName, object value) { 
    PropertyDescriptor propertyDescriptor = GetPropertyDescriptor(component, propertyName); 
    IComponentChangeService svc = GetChangeService(component); 
    IDesignerHost host = GetDesignerHost(component); 
    DesignerTransaction txn = host.CreateTransaction(); 
    try { 
     svc.OnComponentChanging(component, propertyDescriptor); 
     propertyDescriptor.SetValue(component, value); 
     svc.OnComponentChanged(component, propertyDescriptor, null, null); 
     txn.Commit(); 
     txn = null; 
    } finally { 
     if (txn != null) 
      txn.Cancel(); 
    } 
} 

,然后使用它:

[AttributeProvider(typeof (IListSource))] 
public object DataSource { 
    get { return Editor.DataSource; } 
    set { DesignerUtil.SetValue(Component, "DataSource", value); } 
} 

等其他性能。