Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
C# 2008 Step by Step.pdf
Скачиваний:
26
Добавлен:
25.03.2016
Размер:
13.96 Mб
Скачать

 

Chapter 22 Introducing Windows Presentation Foundation

449

Chapter 22 Quick Reference

 

To

Do this

 

Create a WPF application

Use the WPF Application template.

 

 

 

 

Add controls to a form

Drag the control from the Toolbox onto the form.

 

 

 

 

Change the properties of a form or

Click the form or control in the Design View window. Then do

 

control

one of the following:

 

 

In the Properties window, select the property you want to

 

change and enter the new value.

 

 

In the XAML pane, specify the property and value in the

 

 

<Window> element or the element defining the control.

 

 

 

 

View the code behind a form

Do one of the following:

 

 

On the View menu, click Code.

 

Right-click in the Design View window, and then click View Code.

In Solution Explorer, expand the folder corresponding to the

.xaml file for the form, and then double-click the .xaml.cs file that appears.

Define a set of mutually exclusive radio buttons.

Add a panel control, such as StackPanel, to the form. Add the radio buttons to the panel. All radio buttons in the same panel are mutually exclusive.

Populate a combo box or a list box by using C# code

Use the Add method of the Items property. For example:

towerNames.Items.Add(“Upper Gumtree”);

You might need to clear the Items property first, depending on whether you want to retain the existing contents of the list. For example:

towerNames.Items.Clear();

Initialize a check box or radio button

Set the IsChecked property to true or false. For example:

control

novice.IsChecked = true;

 

Handle an event for a control or form

In the XAML pane, add code to specify the event, and then

 

either select an existing method that has the appropriate sig-

 

nature or click the <Add New Event> command on the shortcut

 

menu that appears, and then write the code that handles the

 

event in the event method that is created.

 

 

Chapter 23

Working with Menus and

Dialog Boxes

After completing this chapter, you will be able to:

Create menus for Microsoft Windows Presentation Foundation (WPF) applications by using the Menu and MenuItem classes.

Perform processing in response to menu events when a user clicks a menu command.

Create context-sensitive pop-up menus by using the ContextMenu class.

Manipulate menus through code and create dynamic menus.

Use Windows common dialog boxes in an application to prompt the user for the name of a file.

In Chapter 22, “Introducing Windows Presentation Foundation,” you saw how to create a simple WPF application made up of a selection of controls and events. Many professional Microsoft Windows–based applications also provide menus containing commands and options, giving the user the ability to perform various tasks related to the application. In this chapter, you will learn how to create menus and add them to forms by using the Menu control. You will see how to respond when the user clicks a command on a menu. You’ll learn how to create pop-up menus whose contents vary according to the current context. Finally, you will find out about the common dialog classes supplied as part of the WPF library. With these dialog classes, you can prompt the user for frequently used items, such as files and printers, in a quick, easy, and familiar manner.

Menu Guidelines and Style

If you look at most Windows-based applications, you’ll notice that some items on the menu bar tend to appear repeatedly in the same place, and the contents of these items are often predictable. For example, the File menu is typically the first item on the menu strip, and on this menu you typically find commands for creating a new document, opening an existing document, saving the document, printing the document, and exiting the application.

Note The term document means the data that the application manipulates. In Microsoft Office Excel, it would be a worksheet; in the Bell Ringers application that you created in Chapter 22, it could be the details of a new member.

451

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]