In the first post of this little series we took a look at adding a simple zooming capability to a WPF application. In this post I promised that we'd talk about turning that code in to a reusable component by way of a Decorator. After doing a little research (via Programming WPF) it turns out that a Decorator is not what we want; what we actually want is a ContentControl. Here's what Chris and Ian have to say about ContentControl vs. Decorator:
....[a] reason to derive from ContentControl is to offer a service wrapped around arbitrary content.... this wrapping scenario may seem like the job for which the Decorator was designed. However, there is one critical difference: ContentControl behaves like a Control. This means that it should provide some interactive behaviour [PJ: e.g. such as zooming!].
ContentControl is therefore the base class for wrapper-like elements that provide a specific interactive behaviour around their content, .... whereas Decorator is the base class for lower-level wrapper elements with no particular behaviour, and which either have no appearance or have a fixed appearance [PJ: e.g. such as Border].
Given this little piece of of great advice, coupled with the desire to "do the right thing", this post will not be about decorators, indeed this little series will not be about decorators even though the title says differently :-O
Quite simply we're going to turn our little zooming "loose XAML" into a ContentControl for multiple reuse in our applications.
During this process the control will not change visually, but it will then become a simple step to get zooming into our applications.
The goal, to achieve the screen shot above, should be something as simple as:
<Button Content="I'm some Content" />
The steps to accomplish this will be the topic of the next post in this series, I promise - I'll keep the title the same for the sake of consistency, that'll teach me for prematurely solution-izing.