Visual Studio hints and tips
[This article is for Windows 8.x and Windows Phone 8.x developers writing Windows Runtime apps. If you’re developing for Windows 10, see the latest documentation]
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:
Shortcut | Action |
---|---|
Ctrl+B, E | Enable a bookmark. |
Ctrl+B, T | Toggle a bookmark on or off. |
Ctrl+B, N | Jump to the next bookmark. |
Ctrl+B, P | Jump 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
Shortcut | Action |
---|---|
F7 | Switch from design view to code view |
Shift+F7 | Switch from code view to design view |
Ctrl+] | Jump to a matching brace in code view |
Ctrl+F | Open the Find dialog. |
Ctrl+Shift+F | Open the Find in Files dialog, for searching across your entire project. |
F3 | Go to the next occurrence of a Find item. |
Shift+F3 | Go to the previous occurrence of a Find item. |
Ctrl+I | Start 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+V | Cycle through items in the clipboard, pasting the item copied one item previously. |
Alt+Shift+Enter | Toggles maximizing the code or design view. |
Related topics
Topics for iOS devs
Windows 8 controls for iOS devs
Windows 8 cookbook for iOS devs
Visual Studio links