饭饭TXT > 学习管理 > 《Visual Studio 2010 高级编程(英文出书版)》作者:Nick Randolph/等【完结】 > [Visual.Studio.2010.高级编程].Professional.Visual.Studio.2010.txt

第 10 页

作者:Nick Randolph/等 当前章节:15459 字 更新时间:2026-6-18 14:51

Options dialog.

Because the Start Page is just a WPF control, you could simply create a new WPF control project

and build your page from scratch. However, in most cases it is much simpler to start with the default

Start Page and tailor it to suit your needs. To do this you need to copy the default Start Page from

where it is installed into your Documents folder.

The start Page .

35

1 Copy the contents of the directory C:\Program Files\Microsoft Visual Studio 10.0\

Common7\IDE\StartPages\<culture> into the directory C:\Users\<user name>\

Documents\Visual Studio 10\StartPages (you may need to create this folder because it

may not exist by default).

2 Double-click the project file StartPage.csproj to open the project in Visual Studio 2010,

as shown in Figure 3-2.

As you can see from Figure 3-2, you are able to modify the Start Page using either the WPF designer

or directly in the XAML page. The XAML page is broken down into a number of sections. The

best place to get started is where the TabItem tags are defined for the existing tabs. To create

an additional tab, copy one of the existing tags and modify it to include your own content. For

example, add the following tag after the Latest News tab to add information pertaining to your

company.

fiGure 3-2

xaMl

<!-- Company Tab -->

<TabItem Header=”Company” Height=”Auto” x:Uid=”Company_Tab”

DataContext=”{Binding Links.Content, Converter=

{StaticResource StringToXmlDataProviderConverter}}”>

<Grid>

<Grid.RowDefinitions>

<RowDefinition Height=”Auto”></RowDefinition>

<RowDefinition Height=”*”></RowDefinition>

</Grid.RowDefinitions>

<TextBlock Foreground=”#E8E8E8” Margin=”15” TextWrapping=”Wrap”

x:Uid=”Information_Paragraph” >

The Company has put a lot of effort into writing this custom

36 .

chaPter 3 opTionS And cuSTomizATionS

Start Page so that you can quickly access information relevant to

your job, the projects you are working on etc.

</TextBlock>

</Grid>

</TabItem>

As soon as you save this change, if you click back to the Start Page tab in Visual Studio 2010 you

will notice that your changes have already been applied, giving you a new Company tab, as shown

in Figure 3-3.

fiGure 3-3

Of course, if you want to do away with the default Start Page layout, you can remove any of the

existing elements and replace it with your own layout, information, and functionality. To do this,

select the elements either in the designer or the XAML page and delete them. Then use any of the

WPF controls in your Toolbox to build your own Start Page interface.

code behind with user controls

To extend the functionality of the Start Page further you may want to execute code on particular

events. The Start Page itself doesn’t support having a code-behind file in which to code event

handlers. However, you can encapsulate your functionality into a user control that can then be used

on your Start Page.

With your Start Page project open, created in the previous section, add a new project in which to

place the control you are going to create. To do this, select File . Add . New Project and select

the WPF User Control Library from the Windows node under either the VB or C# node. Give the

project a name, such as CompanyStartPageControls, and click OK. Now, follow these steps to

create a button that launches your company web site:

1 Rename UserControl1.xaml to CompanyPortalControl.xaml in Solution Explorer.

2 Double-click the CompanyPortalControl.xaml file in Solution Explorer to open it in the

designer.

The start Page .

37

3 .

Replace the XAML with the following markup that creates a button with a Click event

handler.

xaMl

<UserControl x:Class=”CompanyStartPageControls.CompanyPortalControl”

xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation”

xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”>

<Grid>

<Button Click=”LaunchWebsite”>Company Website</Button>

</Grid>

</UserControl>

4 Right-click the CompanyPortalControl.xaml file in Solution Explorer and select View

Code.

5 Replace the code with the following, which implements the Click event handler for the

button to launch the company web site.

Vb

Class CompanyPortalControl

Private Sub LaunchWebsite(ByVal sender As Object, ByVal e As RoutedEventArgs)

System.Diagnostics.Process.Start("http://www.builttoroam.com")

End Sub

End Class

c#

namespace CompanyStartPageControls{

public partial class CompanyPortalControl : UserControl{

public CompanyPortalControl(){

InitializeComponent();

}

private void LaunchWebsite(object sender, RoutedEventArgs e){

System.Diagnostics.Process.Start(

@"http://www.builttoroam.com");

}

}

}

You have now created a control with basic functionality encapsulated within it. Follow these steps

to now use this control within your Start Page:

1 .

Right-click the StartPage project within Solution Explorer and select Add Reference. From

the Projects tab, select the CompanyStartPageControls project and click OK.

2 .

Force a rebuild of your solution by selecting the Build . Rebuild Solution menu item.

3 .

Double-click the StartPage.xaml file in Solution Explorer to open the designer.

4 .

In the Toolbox you will now see a tab for CompanyStartPageControls, in which you will

find your CompanyPortalControl. Drag this item onto the StartPage beneath the information

about the Company. The Company TabItem XAML should now look like the following.

38 .

chaPter 3 opTionS And cuSTomizATionS

xaMl

<!-- Company Tab -->

<TabItem Header=”Company” Height=”Auto” x:Uid=”Company_Tab”

DataContext=”{Binding Links.Content, Converter=

{StaticResource StringToXmlDataProviderConverter}}”>

<Grid>

<Grid.RowDefinitions>

<RowDefinition Height=”Auto”></RowDefinition>

<RowDefinition Height=”*”></RowDefinition>

</Grid.RowDefinitions>

<TextBlock Foreground=”#E8E8E8” Margin=”15” TextWrapping=”Wrap”

x:Uid=”Information_Paragraph” >

The Company has put a lot of effort into writing this custom

Start Page so that you can quickly access information relevant to your

job, the projects you are working on etc.

</TextBlock>

<my:CompanyPortalControl Grid.Row=”1” HorizontalAlignment=”Left”

Margin=”6,12,0,0” VerticalAlignment=”Top” />

</Grid>

</TabItem>

If you now save all files (Ctrl+Shift+S) and select the Start Page tab in Visual Studio 2010, you

will see an error as the assembly containing your CompanyPortalControl cannot be found. To fix

this issue, you need to copy the CompanyStartPageControls.dll into the c:\Program Files\

Microsoft Visual Studio 10.0\Common7\IDE\StartPageAssemblies directory. This directory

doesn’t exist by default, so you will need to create it prior to copying the assembly in there.

Once you have copied CompanyStartPageControls.dll, you need to restart Visual Studio. Your

start page should display as shown in Figure 3-4.

fiGure 3-4

If you click the Company Website button, it will launch your company portal in your external web

browser, directly from the Start Page.

Window layout .

39

window layout

If you are unfamiliar with Visual Studio, the behavior of the numerous tool windows may strike you

as erratic, because they seem to appear in random locations and then come and go when you move

between writing code (design time) and running code (run time). In actual fact, Visual Studio 2010

remembers the locations of tool windows in each of these modes. This way you can optimize the

way you write and debug code.

As you open different items from the Solution Explorer, you’ll see that the number of toolbars across

the top of the screen varies depending on the type of file being opened. Each toolbar has a built-in

association to specific file extensions so that Visual Studio knows to display the toolbar when a file

with one of those extensions is opened. If you close a toolbar when a file is open that has a matching

file extension, Visual Studio will remember this when future files with the same extension are opened.

You can reset the association between toolbars and the file extensions via the

Customize dialog (Tools . Customize). Select the appropriate toolbar and click

the Reset button.

Viewing windows and toolbars

Once a tool window or toolbar has been closed it can be difficult to locate it again. Luckily, most

of the most frequently used tool windows are accessible via the View menu. Other tool windows,

mainly related to debugging, are located under the Debug menu.

All the toolbars available in Visual Studio 2010 are listed under the View . Toolbars menu item.

Each toolbar that is currently visible is marked with a tick against the appropriate menu item. You

can also access the list of toolbars by right-clicking in any empty space in the toolbar area at the top

of the Visual Studio window.

Once a toolbar is visible, you can customize which buttons are displayed, either via View .

Toolbars

. Customize or under the Tools menu. Alternatively, as shown in Figure 3-5, if you select the down

arrow at the end of a toolbar you will see a list of all the buttons available on that toolbar, from

which you can check the buttons you want to appear on the toolbar.

fiGure 3-5

40 .

chaPter 3 opTionS And cuSTomizATionS

navigating open items

After opening multiple items you’ll notice that you run out of room across the top of the editor

space and that you can no longer see the tabs for all the items you have open. Of course, you can go

back to the Solution Explorer window and select a specific item. If the item is already open it will

be displayed without reverting to its saved state. However, it is still inconvenient to have to find the

item in the Solution Explorer.

Luckily, Visual Studio 2010 has a number of shortcuts to the list of open items. As with most

document-based applications, Visual Studio has a Windows menu. When you open an item its title

is added to the bottom section of this menu. To display an open item just select the item from the

Windows menu, or click the generic Windows item, which displays a modal dialog from which you

can select the item you want.

Another alternative is to use the drop - down menu at the

end of the tab area of the editor space. Figure 3 - 6 shows

the drop - down list of open items from which you can

select the item you want to access.

Figure 3-6 (right) is the same as Figure 3-6

fiGure 3-6

(left) except for the drop-down icon. This

menu also displays a down arrow, but this one

has a line across the top. This line indicates

that there are more tabs than can fit across

the top of the editor space.

Another way to navigate through the open

items is to press Ctrl+Tab, which displays a

temporary window, as shown in Figure 3-7. It is

a temporary window because when you release

the Ctrl key it disappears. However, while the

window is open you can use the arrow keys or

press Tab to move among the open windows.

The Ctrl+Tab window is divided into three sections, which include the active tool windows, active

files (this should actually be active items because it contains some items that don’t correspond to a

single file), and a preview of the currently selected item. As the number of either active files or active

tool windows increases, the windows expand vertically until there are 15 items, at which point an

additional column is formed.

fiGure 3-7

If you get to the point where you are seeing multiple columns of active files,

you might consider closing some or all of the unused files. The more files Visual

Studio 2010 has open, the more memory it uses and the slower it performs.

If you right-click the tab of an open item, you will see a hidden context menu that gives you

a quick way to do common tasks such as save or close the file that’s associated with the tab. Two

particularly useful actions are Close All But This and the Open Containing Folder. These are

Window layout .

41

self-descriptive as the former closes all tabs other than the one you clicked to get the context menu,

while the latter opens the folder that contains the file in Windows Explorer. Now that all windows

are dockable, there are also actions to Float or Dock as Tabbed Document, which are enabled

depending on what state the tab is in.

docking

Each tool window has a default position, which it will resume when it is opened from the View

menu. For example, View . Toolbox opens the Toolbox docked to the left edge of Visual Studio.

Once a tool window is opened and is docked against an edge, it has two states, pinned and

unpinned. As you saw in Chapter 1, you can toggle between these states by clicking the vertical pin

to unpin the tool window or the horizontal pin to pin the tool window.

You will notice that as you unpin a tool window it slides back against the edge of the IDE, leaving

visible a tag displaying the title of the tool window. This animation can be annoying and time-

consuming when you have tool windows unpinned. On the Environment node of the Options dialog,

you can control whether Visual Studio should automatically adjust the visual experience based on client

performance. Alternatively, you can elect to uncheck the Enable rich client visual experience option.

Most developers accept the default location of tool windows, but occasionally you may want to

adjust where the tool windows appear. Visual Studio 2010 has a sophisticated system for controlling

the layout of tool windows. In Chapter 1 you saw how you could use the drop-down, next to the

Pin and Close buttons at the top of the tool window, to make the tool window floating, dockable, or

even part of the main editor space (using the Tabbed Document option).

When a tool window is dockable, you have a lot of control over where it is positioned. In Figure 3-8

目录
设置
设置
阅读主题
字体风格
雅黑 宋体 楷书 卡通
字体大小
适中 偏大 超大
保存设置
恢复默认
手机
手机阅读
扫码获取链接,使用浏览器打开
书架同步,随时随地,手机阅读
首 页 < 上一章 章节列表 下一章 > 尾 页