Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
CSharp_for_Beginners.doc
Скачиваний:
32
Добавлен:
23.11.2019
Размер:
2.4 Mб
Скачать

Стандартные элементы управления wpf

В следующей таблице перечислены наиболее распространенные элементы управления WPF, которые можно найти на вкладке Стандартные панели элементов.

Имя элемента управления

Описание

System.Windows.Controls.Border

Отображает рамку вокруг содержимого.

System.Windows.Controls.Button

Позволяет пользователю выполнить действие, нажав кнопку. Событие Buttonbase.Click возникает при щелчке элемента управления Button.

System.Windows.Controls.CheckBox

Позволяет пользователю устанавливать и снимать флажок для выбора значения типа "Yes/No" или "True/False".

System.Windows.Controls.ComboBox

Позволяет пользователю выбрать элемент в раскрывающемся списке. Список отображается при щелчке стрелки раскрывающегося списка.

System.Windows.Controls.Grid

Определяет гибкую область сетки, состоящую из столбцов и строк.

System.Windows.Controls.Image

Выводит изображение.

System.Windows.Controls.Label

Выводит текст в форме. Обеспечивает поддержку клавиш доступа.

System.Windows.Controls.ListBox

Enables a user to select an item from a list.

System.Windows.Controls.RadioButton

Enables a user to choose from among mutually exclusive items. The selection of one radio button is mutually exclusive to any other radio button in the same container.

System.Windows.Controls.StackPanel

Enables you to stack child controls vertically or horizontally.

System.Windows.Control.TabControl

Enables visual content to be arranged in a tabular form.

System.Windows.Controls.TextBox

Displays unformatted text and enables users to enter text.

Additional controls available in the Toolbox include the following:

  • Container controls, such as System.Windows.Controls.Canvas, System.Windows.Controls.DockPanel, and System.Windows.Controls.Frame. For more information, see WPF Container Controls Overview.

  • Menus and Toolbars, such as System.Windows.Controls.Menu, System.Windows.Controls.ToolBar, and System.Windows.Controls.Primitives.StatusBar.

  • Document controls, such as System.Windows.Controls.DocumentViewer and System.Windows.Controls.FlowDocumentPageViewer.

System.Windows.Controls.ListBox

Позволяет пользователю выбрать элемент в списке.

System.Windows.Controls.RadioButton

Позволяет пользователю выбрать один из взаимно исключающих элементов. Выбор одного из переключателей исключает выбор любого другого в том же контейнере.

System.Windows.Controls.StackPanel

Позволяет располагать дочерние элементы управления горизонтально или вертикально.

System.Windows.Control.TabControl

Позволяет располагать визуальное содержимое в табличной форме.

System.Windows.Controls.TextBox

Отображает неформатированный текст и позволяет пользователям вводить текст.

Дополнительные элементы управления, доступные на панели элементов.

  • Вмещающие элементы управления, например System.Windows.Controls.Canvas, System.Windows.Controls.DockPanel и System.Windows.Controls.Frame. Дополнительные сведения см. в разделе Общие сведения о контейнерных элементах управления WPF.

  • Меню и панели инструментов, например System.Windows.Controls.Menu, System.Windows.Controls.ToolBar и System.Windows.Controls.Primitives.StatusBar.

  • Элементы управления для документа, например System.Windows.Controls.DocumentViewer и System.Windows.Controls.FlowDocumentPageViewer.

How to: Create Event Handlers for WPF Controls

You can add the default event handler for many controls by double-clicking the control in Design view. You can also create an event handler for controls in a Windows Presentation Foundation (WPF) application by adding an attribute to the control's XAML representation. This XAML markup defines the event and the name of the method that will handle the event. Then, you write the code for the method in the Code Editor.

To create an event handler for a button

  1. Create a WPF application by using Visual C# Express Edition. For more information, see How to: Create a New WPF Application Project.

  2. Drag a Button from the Toolbox to the WPF window, and then select the button.

  3. Double-click the button.

The Click event handler is created and the cursor is positioned in the event handler in the Code Editor.

  1. Add the following code to the event handler:

    MessageBox.Show("Event handler was created by " + "double-clicking the button.");

  2. Drag a second Button control from the Toolbox to the WPF design surface, and then select the button.

  3. Add an attribute named Click to the Button element in the XAML editor, and set its value to ButtonOKClicked. This is the name that you will give the event handler in code. For example, the attribute can be written as follows: Click="ButtonOKClicked".

  4. Right-click the designer and then click View Code.

  5. Add the following event handler to the Window1 class. This code displays a message whenever you click the button.

    private void ButtonOKClicked(object sender, RoutedEventArgs e)

    {

    MessageBox.Show("Event handler was created manually.");

    }

  6. Press F5 to run the program.

  7. When the window appears, click a button.

  8. Verify that the correct text appears in a message box when you click each button, and then close the application.

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