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

Using data templates

In previous recipes we showed some Person objects as strings, whether it's the ToString implementation or some specific property. Text is not the only option. Even with text, we may want to change its properties, such as fonts and colors. WPF provides a powerful way to visualize data using the concept of data templates. In this recipe, we'll see how to create and use such templates.

Getting ready

Make sure Visual Studio is up and running.

How to do it...

We'll create a simple application that shows Person objects in a more interesting way using data templates.

  1. Create a new WPF Application named CH06.DataTemplates.
  2. Add a new class named Person, with an Age and Name properties, similar to the previous recipe.
  3. Open MainWindow.xaml ...

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