Most developers I know are obsessive about managing their software workspace. When you spend countless hours sitting at your laptop creating software, the last thing you want to do is wait on your tools. From setting up keyboard shortcuts to installing your favorite utilities, you know just how to squeeze every drop of performance from your tools so that you can write code fast and furious. WPF developers are no different. Here are a couple tips to speed up the WPF tools in Visual Studio.
Speeding up the designer
Visual Studio supports a plug-in designer model. The .NET Windows Forms designer is a great example of a designer plug-in: when you open a Windows Forms file in Visual Studio, the IDE determines that the Forms class has an affiliated custom UI designer. The designer is loaded into an IDE tab, your code is parsed and the designer renders your UI. Any changes you make to your form, like dragging a button from the ToolBox to the design surface, causes the designer to update the code in YourForm.designer.cs as well as forcing an update to the UI.
WPF UserControls, Pages and Windows designers work the same way. When you open a XAML file, Visual Studio finds the matching WPF designer and loads your XAML into it. If you use this WPF designer for more than few days, however, you'll begin to realize that it is slow, especially when loading large files.
This is a well-known problem, and the WPF designer team at Microsoft (codenamed Cider) is making good progress toward fixing the problem. In the meantime, they have added a setting that makes it easy to speed things up by disabling the designer's normal WYSIWYG view and using the XAML view instead.
- Open the 'Tools-Options' menu.
- Select the 'Text Editor-XAML-Miscellaneous' node.
- Check the 'Always open documents in full XAML' view checkbox.
Change the default XAML editor
The simplest change to make to speed up the loading of XAML files is to forget about using the WPF designer altogether. Instead, set the default editor for XAML files to the XML editor. You still get full IntelliSense support while editing XAML, but the load time for most files is dramatically reduced. Making this change is simple.
- Right-click a XAMLfile in the Solution Explorer.
- Choose the 'Open With…' menu item.
- Select the 'Source Code (Text) Editor' item and click the 'Set as Default' button.
The disadvantage with this approach is that you no longer see the XAML/Designer tabs in the editing window. If you do need to work with the designer, choose the 'View-Open With' menu item, and Visual Studio will open the file in another tab.
Walt has trained thousands of corporate developers during the last 14 years and he travels the world speaking at software conferences, and providing developer training for corporations. He writes for several IT magazines, and worked on books/videos and .NET courses for Microsoft Press. As a Wintellect consultant he is presently focused on the WPF, Surface and Silverlight APIs. Walt is also a Microsoft MVP, WPF Disciple, Silverlight Insider and author of the free Shazzam WPF Shader utility.