简体   繁体   English

用于Visual Studio的IProvideClassInfo属性面板的添加项

[英]IProvideClassInfo for Visual Studio Add In for Properties Panel

I am creating a Visual Studio Package for VS 2010 using VB.Net that contains a custom editor. 我正在使用包含自定义编辑器的VB.Net创建VS 2010的Visual Studio程序包。 The editor presents many items in ListViews. 编辑器在ListViews中显示许多项目。 I want the item selected (its parent and any child items) to appear in the PropertyGrid panel object list to allow for property edits. 我希望选定的项(其父项和任何子项)出现在PropertyGrid面板对象列表中,以允许进行属性编辑。 I have this working. 我有这个工作。 Normally the drop down list of selectable items appears with the name of the item in bold text followed by the type name for that object. 通常,可选项目的下拉列表会以粗体显示该项目的名称,后跟该对象的类型名称。 In my package I cannot get the bold name to appear, only the type name. 在我的程序包中,我无法显示粗体名称,只能显示类型名称。

http://msdn.microsoft.com/en-us/library/vstudio/bb165752(v=vs.100).aspx http://msdn.microsoft.com/zh-CN/library/vstudio/bb165752(v=vs.100).aspx

This page is the only piece of information I can find on naming an object in the object list. 在对象列表中命名对象时,此页面是唯一可以找到的信息。 As the link states, I implemented IProvideClassInfo in the objects I'm giving to VS to display in the list but the GetClassInfo method is never called and no name is displayed. 如链接所示,我在给VS的对象中实现了IProvideClassInfo以显示在列表中,但是从未调用GetClassInfo方法,并且不显示名称。 Each object also has a public property called "Name" as well just in case that worked. 每个对象还具有一个称为“名称”的公共属性,以防万一。 It did not. 它没。

Can anyone tell me what I'm doing wrong? 谁能告诉我我在做什么错?

Searching the forum on MSDN I finally found someone answering this question. 在MSDN上搜索论坛后,我终于找到有人回答这个问题。

IProvideClassInfo has nothing to do with this like the link I gave states. IProvideClassInfo与此无关,就像我给出的链接一样。 The correct answer is to implement the ICustomTypeDescriptor interface in your objects. 正确的答案是在您的对象中实现ICustomTypeDescriptor接口。 Most of the function implementations involve returning the result of the same function call on the TypeDescriptor object (shared/static functions). 大多数函数实现都涉及在TypeDescriptor对象(共享/静态函数)上返回相同函数调用的结果。 The GetComponentName result will be the bold part of the drop down. GetComponentName结果将是下拉菜单中的粗体部分。 The GetClassName result will be the non-bold part. GetClassName结果将为非粗体部分。 I'm not sure what the GetEditor function does but returning the TypeDescriptor.GetEditor result causes an infinite loop, returning Nothing/null seems to work. 我不确定GetEditor函数的作用,但返回TypeDescriptor.GetEditor结果会导致无限循环,返回Nothing / null似乎有效。

I created a base class for all my objects that will go into the Property panel's drop down that implements all the functions where GetClassName returns Me.GetType().Name and GetComponentName returns Me.ToString() 我为所有对象创建了一个基类,该基类将进入“属性”面板的下拉列表,该下拉列表实现了GetClassName返回Me.GetType()。Name和GetComponentName返回Me.ToString()的所有功能。

It works great. 效果很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM