How do I create a command in Visual Studio 2010 to toggle between an aspx code behind and the file's markup, or source view?
In Visual Studio 2010 if I open a aspx pages code behind file then press F7 which is bound to the View.ToggleDesigner command by default I am taken to the aspx files WYSIWYG design view. To get to the actual markup, or source view, I then need to press Shift-F7.
I would like a command in visual studio that would toggle back and forth between the code behind and the aspx file's markup, or source view, ignoring the design开发者_JAVA技巧 view. A reasonable name for the command would be View.ToggleMarkup. Often times I add tags to the markup by hand, give them an ID and runat=Server attribute then switch to the code behind to add behavior or control the appearance of these new elements so this visual studio command would come in handy I believe.
So how would I create this hypothetical command View.ToggleMarkup?
After looking for this same thing for a little while, the only way I got it to work was by using Macros.
Tools -> Macros -> Macros IDE
- Create a new Module
- Copy this code inside the Module How to switch between view source and markup view in Visual Studio? thanks to Viktar Karpach
- Assign a shortcut key F7 to this Macro like this How To Configure And Use Visual Studio Macros
Personally, I modified the Macro source code and added the support to masterpages too by adding this line
InStr(activeDoc, ".master") Or _
I hope it helps
I found that Shift+F8 will do the trick.
精彩评论