Sheridan College
PROG 37721
WPF Controls Week 5-2 User Interaction Controls
Click to edit Master title style
2
• B u t t o n C o n t r o l
• C h e c k B o x C o n t r o l
• L i s t B o x , C o m b o B o x C o n t r o l
• Te x t B o x C o n t r o l
2
User Interaction Controls
Part - 3
Click to edit Master title style
3
3
• Some of the common user inte
...[Show More]
WPF Controls Week 5-2 User Interaction Controls
Click to edit Master title style
2
• B u t t o n C o n t r o l
• C h e c k B o x C o n t r o l
• L i s t B o x , C o m b o B o x C o n t r o l
• Te x t B o x C o n t r o l
2
User Interaction Controls
Part - 3
Click to edit Master title style
3
3
• Some of the common user interactions controls are:
• Button: Lets the user click to tell the program to do something.
• CheckBox: Lets the user select or deselect a non-exclusive option.
• ComboBox: Lets the user pick from a dropdown list of choices.
• ListBox: Displays a list of items to the user.
• Menu: Displays a main menu for a window.
• PasswordBox: Lets the user enter text while hiding the text on the screen.
• RadioButton: Lets the user select one of an exclusive set of options.
• Slider: Lets the user select a numeric value from a range of values.
• TextBox: Lets the user enter text without fancy formatting.
User Interaction Controls
Click to edit Master title style
4
4
• The Button control lets the user click to tell the program to do
something.
• When the user clicks a Button, the Button raises its Click event.
• The program catches the event and takes whatever action is
necessary.
• A Button's Content property
can contain a single child, but
that child can be a container
such as a Grid or StackPanel,
so you can put just about
anything you want in a Button.
The Button Control
Click to edit Master title style
5
5
The Button Control
• XAML Code:
<Button Content="Show Time" x:Name="btnShowTime"
Width="150" Height="50" Margin="5"
Click="btnShowTime_Click" />
private void btnShowTime_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show(DateTime.Now.ToString());
}
• C# Code Behind:
Click to edit Master title style
6
6
• A CheckBox control lets the user select or unselect an option.
• User can select multiple checkboxes from the checkbox group.
• Two of the CheckBox class's most useful events are Checked and
Unchecked.
• Fired when the user checks or unchecks the control.
• The control’s important property is
IsChecked.
• This property can take the values
True (checked) and False (unchecked).
• The program can use IsChecked to get
or set the control's current state.
The CheckBox Control
Click to edit Master title style
7
7
The CheckBox Control
• XAML Code:
<CheckBox Content="Street Luge" IsChecked="True"
x:Name="chkStreetLuge" />
private void btnRead_Click(object sender, RoutedEventArgs e)
{
if (chkStreetLuge.IsChecked)
MessageBox.Show("Street Luge");
[Show Less]