This tutorial explores common Windows Presentation Foundation (WPF) controls and demonstrates how to use them to build interactive user interfaces. WPF provides a rich set of controls for various UI elements, from basic input fields to complex data displays.
Common Controls
Button
The Button control is a fundamental element used to trigger an action. It can contain text, images, or other content.
Example: Simple Button
Click the button to see a message.
<Button Content="Click Me" />
TextBox
The TextBox control allows users to enter and edit text. It supports single-line and multi-line input.
Example: Text Input
Enter your name:
<TextBox Text="Enter text here" />
Label
The Label control displays static text, often used to provide descriptions for other controls.
Example: Label for Input
<Label Content="Email:" />
<TextBox ... />
CheckBox
The CheckBox control represents a binary state (checked or unchecked), often used for options.
Example: Option Selection
<CheckBox Content="Enable notifications" />
RadioButton
RadioButton controls are used when you want to allow the user to select only one option from a group.
Example: Radio Button Group
Select your preferred method:
<StackPanel>
<RadioButton Content="Email" GroupName="ContactMethod" />
<RadioButton Content="Phone" GroupName="ContactMethod" />
</StackPanel>
ComboBox
A ComboBox combines a list box with a text box, allowing users to select an item from a dropdown list or type their own value.
Example: Dropdown Selection
Choose a framework:
<ComboBox>
<ComboBoxItem Content="WPF" />
<ComboBoxItem Content="Windows Forms" />
<ComboBoxItem Content="UWP" />
</ComboBox>
Interactive Elements and Events
Controls are made interactive through events. For example, a button's Click event can be handled to perform specific actions. We will delve deeper into event handling in a subsequent tutorial.
Next Steps
Now that you're familiar with the basic WPF controls, learn how to connect them to data sources using data binding.