O'Reilly logo

Windows Presentation Foundation 4.5 Cookbook by Pavel Yosifovich

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating and using styles

Styles provide a convenient way to group a set of properties (and triggers) under a single object, and then selectively (or automatically as we'll see later) apply it to elements. In this recipe, we'll create some styles and apply them to elements to show how useful these are in any application.

Getting ready

Make sure Visual Studio is up and running.

How to do it...

We'll create a calculator-like user interface and use styles to change its look:

  1. Create a new WPF Application named CH08.StyledCalculator.
  2. Open MainWindow.xaml and change the following Window properties:
    Title="Styled Calculator" SizeToContent="WidthAndHeight"
    ResizeMode="CanMinimize"
    
  3. Add four columns and five rows to the existing Grid, all with auto sizing:

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required