Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

21. Templates

21. Templates

In the last chapter we saw how you can use resources, styles and triggers to simplify defining the appearance and visual behavior of a WPF control, but the basic structure of the elements remained the same—we changed the size and color of a button, and made it move around, but it still looked like a button. In this chapter, we’ll take control of that structure as well by using WPF templates to re-define the visual tree of any FrameworkElement or FrameworkContentElement.

Want your buttons to be triangular? No problem. Does your application really require an oval window? You can make that happen using templates.

We’ll start by examining some fundamental elements you can use to build your new versions of controls, and then we’ll look at the very simple process of re-defining the control’s appearance. We’ll also explore the technique for making your new template reflect the control properties you set at design- and runtime. Finally, we’ll look at a new way of specifying visual behavior, similar to a trigger but available only within a control template.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial


 Â