Code snippets are a very useful feature of Visual Studio. We've added some key snippets to the ArcGIS Explorer SDK – the kinds of things that are simple but that you end up writing frequently, or that you might forget. Even some of the team members forget this stuff and have been pleased to be reminded of the snippets, so we know that you'll find these very useful.

For example, it’s easy to forget how to get hold of the application objects when coding from scratch, so we added a code snippet for every one of the static members that allow you to drill in to the ArcGIS Explorer object model. It’s also easy to forget that including the SuspendDrawing method call in a Using statement will ensure the drawing is resumed correctly; so we added a code snippet for this. These snippets are available in both Visual Basic and Visual C#, and you may have accessed them by right-clicking in the code window and choosing Insert Code Snippet, then Explorer:

BUT there is an even easier way to do this. To get a reference to the currently active View, just type “active” in the code window; you’ll see the  intellisense in Visual Studio listing the activeMapDisplay keyboard shortcut to the ‘Get ActiveMapDisplay from Application’ snippet. Just hit Tab and the snippet is inserted.



If you forget what snippets are available, or want to look up a keyboard shortcut, you can use the Visual Studio Code Snippet Manager to browse the Explorer snippets including their keyboard shortcuts.



Here's a table of Visual Basic and Visual C# code snippets currently in the SDK for your convenience.

Code snippets are not just for VB and C# code though, they are also useful when you’re working declaratively with application conditions. These are pre-defined application states that can be used to determine when Buttons, DockWindows, and Galleries are enabled or disabled. For more information see the ArcGIS Explorer application conditions SDK Help topic.


You can set an application condition for a new customization when you create it using the New Item wizards which are part of the ArcGIS Explorer Tools for Visual Studio. For more information see the Visual Studio tools for ArcGIS Explorer SDK Help topic.



Open the Addins.xml file in your add-in project and for the XML element describing the add-in class. You will see an attribute named condition with a text string indicating the application condition you picked (note that if you chose the Always option in response to When should the Button be enabled, there will be no condition attribute at all in your XML).


Changing an application condition is easy to do by making use of the XML code snippets. Right click in the XML file and choose Insert Code Snippet, then Explorer. You will see a list of all the application conditions you can apply; choosing a condition snippet will add the correct text string to the XML file.


Note that the application conditions XML code snippets do not have intellisense and keyboard shortcuts - that’s something we’re working on for a future release. Let us know what you think of the snippets, and what kind of snippets you’d like to see in the future.