#298 – Button Basics – Content and Click

The Button control in WPF represents a visual representation of a button that a user can click on.  It will typically initate some action.

Here’s an example, with two buttons.

You specify a button’s content–typically a text label–using the Content property.  Like other controls that descend from FrameworkElement, you can specify the height and width using the Height and Width properties.

		<Button Content="Save" Height="25" Width="80" />

You can execute some piece of code when the user clicks on the button by adding an event handler for the button’s Click event.

First, attach the handler in the XAML:

		<Button Content="Save" Height="25" Width="80" Click="Save_Click"/>

Then, define the corresponding method in the code-behind class:

        private void Save_Click(object sender, RoutedEventArgs e)
            MessageBox.Show("You clicked on the Save button");

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: