Visual Studio hints and tips

Applies to Windows and Windows Phone

Here's how to become as comfortable in Microsoft Visual Studio as you are in Xcode.

The following video provides a brief comparison of Xcode and Visual Studio.

Running and stopping your app

The simplest way to run your app is to press F5. This will build and launch it (assuming there are no compile errors) in Debug mode (use Crtl+F5 to launch without Debug mode). Your app can either run in the simulator, or on your computer (Local machine). If running on your local machine, press Windows + D to return to the desktop, and then stop it running by pressing Shift+F5.

The simulator may overlay numbers at the top of the screen measuring the current framerate. You can alter these settings by opening the App.XAML.cs file and changing any calls to DebugSettings.EnableFrameRateCounter.

Note  If you are using Visual Studio under emulation on your Mac, the function (F) keys may not work as you expect. Please refer to your emulation application's documentation regarding remapping keyboard shortcuts.

Breakpoints

As with Xcode, clicking in the margin of a line of code in Visual Studio will introduce a breakpoint. Pressing F9 will toggle the breakpoint on and off.

Resolve references

If you enter code such as Debug.WriteLine("Hello") but Debug appears in red, this is probably because you have not entered a using directive at the start of your C# class. To quickly correct this error, right-click on the item in red and select Resolve from the pop-up menu. You can then elect to have the using directive added automatically, or to prefix the correct namespace path directly to the object.

Bookmarks

Bookmarks are locations in your source code maintained by Visual Studio. They are not breakpoints, they are purely to help you quickly jump around your project. Access bookmarks from the Bookmarks menu under the EDIT menu, or use these keyboard shortcuts:

ShortcutAction
Ctrl+B, EEnable a bookmark.
Ctrl+B, TToggle a bookmark on or off.
Ctrl+B, NJump to the next bookmark.
Ctrl+B, PJump to the previous bookmark.
Ctrl+]Jump to matching brace in code view.

 

Snippets

Snippets are commonly used pieces of C# code which you can quickly drop into your project. Snippets speed up entering code, and reduce typing errors. You can read about them here: How to: Use Code Snippets (C#) , or just enter Ctrl+K, Ctrl+X in Visual Studio to try it out.

Other useful keyboard shortcuts

ShortcutAction
F7Switch from design view to code view
Shift+F7Switch from code view to design view
Ctrl+]Jump to a matching brace in code view
Ctrl+FOpen the Find dialog.
Ctrl+Shift+FOpen the Find in Files dialog, for searching across your entire project.
F3Go to the next occurrence of a Find item.
Shift+F3Go to the previous occurrence of a Find item.
Ctrl+IStart a Incremental search: as you type, occurrences are highlighted which you can jump between with F3 and Shift+F3.
Ctrl+,Opens a dialog. Type the name of your method, class, variable and so on and immediately jump to the code.
Shift+Ctrl+VCycle through items in the clipboard, pasting the item copied one item previously.
Alt+Shift+EnterToggles maximizing the code or design view.

 

Related topics

Topics for iOS devs
Resources for iOS devs
Windows 8 controls for iOS devs
Windows 8 cookbook for iOS devs
Visual Studio links
Code libraries, toolkits and other sources of help
Developer downloads for programming Windows Store apps

 

 

Show:
© 2014 Microsoft