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.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Preview
Unable to display preview. Download preview PDF.
Rights 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
DOI: https://doi.org/10.1007/978-1-4302-0612-5_7
Publisher Name: Apress
Print ISBN: 978-1-59059-976-1
Online ISBN: 978-1-4302-0612-5
eBook Packages: Professional and Applied ComputingProfessional and Applied Computing (R0)Apress Access Books