user1228
user1228

Reputation:

Access the project file structure within the Visual Studio Properties property grid?

I'm making a Component that will be used in a VS drag and drop designer. One of the properties on this component needs to be the pack URI of a file within the project.

I'd like to make things a little easy and, from within the property editor the PropertyGrid uses for my type's property, examine the solution, construct the Uris and present them to the user for choosing.

Is this possible? And, if so, can I get some pointers and where-to-starters on how to go about this?

Upvotes: 0

Views: 1057

Answers (2)

amazedsaint
amazedsaint

Reputation: 7642

I think there are a couple of peices to this.

1) You can create your own type editors for a property, to decide how the property values are presented to the users using the property grid.

For this, you need to create a type editor, inheriting from UITypeEditor, like this.

public class UriListUIEditor : UITypeEditor
{
       //Override a couple of methods
}

Have a look at this codeproject article to see a simple example. http://www.codeproject.com/KB/edit/flagenumeditor.aspx

Now, provide the EditorType attribute of your property, like

   [Editor(typeof(Utils. UriListUIEditor ), 
             typeof(System.Drawing.Design.UITypeEditor))]
    public string Uri 
             { get;set;
             }

2) To iterate solutions in your project, get the current DTE Instance

 var dte = (EnvDTE80.DTE2)System.Runtime.InteropServices.Marshal. GetActiveObject("VisualStudio.DTE.8.0"); 

And Iterate through all the projects to build the list or URIs or anything. Ideally you do this inside the EditValue method of the above UriListUIEditor.

  foreach (var project in dte.Solution.Projects)
        {

        }

Hope this helps

Upvotes: 1

Sai Ganesh
Sai Ganesh

Reputation: 300

Is this a component that is for WPF projects only? Then you may be in luck. Here's a write up. http://www.wiredprairie.us/journal/2007/06/pack_syntax_in_wpf.html. Or this MSDN sample may help http://msdn.microsoft.com/en-us/library/aa972152(VS.85).aspx

Upvotes: 1

Related Questions