#12 – Markup and Code Behind

WPF applications are made up of markup (XAML) and code-behind (managed code).  The markup defines the layout and appearance of the application, whereas the code-behind defines the behavior.

WPF markup is written using XAML, a declarative markup language based on XML.  The XAML lists the controls that make up the application, how they are related, and how they appear.

<Grid>
    <StackPanel>
        <Button Content="Save" Height="23" Name="btnSave" Width="75" Click="btnSave_Click" />
        <Button Content="Load" Height="23" Name="btnLoad" Width="75" Click="btnLoad_Click" />
    </StackPanel>
</Grid>

The code-behind is the part of your application that exists as managed code (e.g. C#) and describes the behavior of the application at runtime.

private void btnSave_Click(object sender, RoutedEventArgs e)
{
    // Do actual work of saving file here
}
Advertisements

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 )

Google+ photo

You are commenting using your Google+ 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: