Skip to main content

ControlTemplates, Styles, and Custom UserControls

  • Chapter
Foundation Expression Blend 2
  • 215 Accesses

Abstract

What this chapter covers:

  • Understanding ControlTemplates

  • How Styles work with ControlTemplates

  • Creating a Button ControlTemplate

  • Creating Styles and using them to overwrite WPF controls

  • Using Styles to mandate how controls display their content

  • Using ResourceDictionaries

  • Applying resources to WPF controls

  • Using Styles and ControlTemplates to create your own custom WPF UserControls

  • How to create and use custom UserControls

A very important concept in object-oriented programming is one that says you can create something once and then reuse it over and over again. Of course, this means you can reuse a resource in one application, but in WPF you can take this further and reuse a resource over and over again in other applications. ControlTemplates and UserControls allow you to do just that. I have been working with WPF now for well over a year, and in that time I have been able to create my own libraries of resources that I am now able to reuse in new applications that I create. This allows me to develop new applications faster because I don’t have to re-create new resources, but rather add a reference to them in my new applications and then simply make use of them. In this chapter, you are going to create a Style for a WPF Button control that will contain a ControlTemplate, and then change that ControlTemplate to have the Button show an Image control. You are then going to create a ResourceDictionary and move the Button Style to it. Finally, you are going to take everything you have learned and create a custom UserControl.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 29.99
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 39.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

Rights and permissions

Reprints and permissions

Copyright information

© 2008 Victor Gaudioso

About this chapter

Cite this chapter

(2008). ControlTemplates, Styles, and Custom UserControls. In: Foundation Expression Blend 2. Apress. https://doi.org/10.1007/978-1-4302-0612-5_7

Download citation

Publish with us

Policies and ethics