#1,159 – Managing using Directives, part II

You can add missing using directives by using the Resolve command.  You can also clean up the current list of using directives in a file, removing the ones that are no longer needed.

You can remove unneeded using directives by clicking anywhere within a file and selecting Organize Usings | Remove Unused Usings.

In the example below, we start out with 20 using directives at the top of the file.

1159-001

We then select Remove Unused Usings.

1159-002

After we execute this command, we’re left with only four using directives at the top of the file.

1159-003

#1,158 – Managing using Directives, part I

As you write code, Visual Studio will let you know that you’ve used an identifier that it doesn’t know by marking it with a red squiggly underline.  Below, we’ve started creating a class that derives from Shape.  But Visual Studio tells us that it doesn’t know about Shape.

1158-001

The easiest way to resolve this is to try right-clicking on the unknown identifer and selecting the Resolve entry.  Visual Studio will give you a list of namespaces that it can find the identifier in.  You can then select one of these options and Visual Studio will add the relevant using directive.

1158-002

 

1158-003

Note that this will only work if the identifer is valid somewhere within the assemblies that your project has referenced.  If you have correctly spelled an identifer and the Resolve option does not appear, you will need to add a reference to the assembly where the identifier in question is defined.

 

 

#994 – Viewing the Visual Tree from within Visual Studio

A visual tree in WPF is the complete hierarchy of all visual elements that make up your user interface.  The visual tree will contain lower-level elements that are not necessarily part of the higher-level logical tree, as defined in your XAML.

You can view the visual tree for UI elements in an WPF application from within Visual Studio, as follows.

Add a breakpoint in the code for your main window that occurs after the application has loaded.  In the example below, we break after pressing a Button.

In the Locals window, find the object representing your main window.  In the Value column, hover over the magnifying glass and notice that it’s labeled WPF Tree Visualizer.

994-001

 

Click on the magnifying glass to open the WPF Tree Visualizer.  The WPF Tree Visualizer will open in a new window.  You can view the Visual Tree in the upper left corner of the window.

994-002

#723 – Turning Off All Caps Menus in Visual Studio 2012

One of the changes in Visual Studio 2012 was to render the main menus in all caps.  This was done to better match the new Metro (Windows Store) style of user interface, used across other Microsoft products.  (E.g. Office 2013 or the Bing web site).

747-001

However, many people have argued that using all caps make the user interface less readable and constitutes bad typography.

If you prefer using upper and lowercase in the main menu, you can turn off the all caps by adding a value in the registry.

In the key HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\11.0\General, create a DWORD value named SuppressUppercaseConversion and set its value to 1.

You’ll now get upper and lowercase in the menus.

747-002

#722 – Get a Free Copy of Visual Studio 2012

You can start developing WPF applications by using the Visual Studio 2012 Express edition listed below.  This edition is free and allows you to create WPF applications for the desktop.

  • Visual Studio Express 2012 for Windows Desktop

Additionally, you can get a free copy of Visual Studio Team Foundation Server Express 2012, which allows up to five developers to do source code control, work item tracking, and build automation.

#413 – Creating a Grid from the Visual Studio Designer

You can create a Grid element by editing XAML directly, but you can also create the Grid and set its properties from within the designer in Visual Studio.

Start by finding the Grid control in the toolbox.

Double-click the entry in the toolbox, or left-click and drag it onto your design surface, to create a Grid element.  You’ll see the Grid show up in XAML and in the designer.

You can add rows and columns from within the designer by clicking on an empty area of the blue borders at the top and left of the Grid.  Small blue arrows will indicate the rows/columns added.

You can change row/column sizes by dragging the blue arrows.  You can also change the GridUnitType of a row/column, dictating how it will calculate its size.

Everything that you do will also be reflected in the XAML.


#294 – Intellisense Is Also Available in the XAML Editor

In Visual Studio, Intellisense works in not only the code editor, but also the XAML editor.  As you being typing an element name, for example, Intellisense will display a window listing possible elements.

If you press TAB while an element is highlighted, Intellisense will insert the entire element name into the XAML.

As you continue typing, Intellisense will display a list of possible attributes that are appropriate for the current element.

Again, you can press TAB to insert the complete attribute name.  Intellisense will also add an equals (=) sign and a pair of quotation (“) marks.

Intellisense is also available when entering binding expressions.

#293 – Intellisense Will Show Overloaded Methods

Intellisense in Visual Studio presents you with a list of possible methods that you can call, based on what you’ve already typed.  If there are overloaded methods available in the current context, it will let you cycle through a list of the methods.  Overloaded methods are methods that have the same name, but a different argument list and/or return type.

In the example below, there are three different methods named Bark in the Dog class.  After you’ve entered the full method name and the opening parenthesis, Intellisense displays information about the first of the three methods.  The first overload of Bark takes a single int parameter.

If you press the down arrow key, or click on the downward facing arrow icon, Intellisense shows you the second of the three methods.

You can press the down arrow key again to see the third overload.

#292 – Intellisense Includes Information About a Method’s Parameters

Intellisense will display not only a list of methods that match what you’ve already typed, but will also show you information about the method’s parameters.

Assume that you begin entering the name of a method in the Dog class.  Intellisense shows you information about the  method.

If you now press the Tab key, Visual Studio will fill in the complete method name.

If you now enter an opening parenthesis, Intellisense will list the name of the Bark method again, with the first parameter in bold and a description of the first parameter.  (The method and parameter information will only be displayed if the class has defined the appropriate XML Documentation elements).


At this point, you can enter a value for the first parameter and then enter a comma.  Intellisense displays information about the second parameter.

#291 – Intellisense Lists Available Methods and Properties

When you type a period (.) after a variable that is a reference-typed variable, Intellisense in Visual Studio will display a list of relevant class members.

In the example below, the variable d is an instance of the Dog class.  When you enter a period (.) after the variable name, Intellisense displays a list of the members of the Dog class.  This includes both methods and properties.

You can use the arrow keys to select a specific class member.  As each class member is highlighted, information about the method or property is display to the right.