Content controls provide a flexible way of customizing the appearance of a control. The ContentControl
class includes a Content
property, of type object; meaning, it can be anything. A typical example is a Button
. The Button
inherits from ContentControl
(not directly, but this is unimportant for this discussion). A typical button shows text, an image, or perhaps an image and text. But in fact, it can hold anything, such as a graphic drawing, a video playing, any combination of the above, or anything else. This is the power of ContentControl
. Let's see how this works.
We'll create several buttons (which are ContentControl
s) and show the various ways their content can be set and viewed:
Create a new WPF Application named
CH04.ContentControls
.Open
MainWindow.Xaml
. Change the rootGrid
to aStackPanel
.Add a
Button
to theStackPanel
and set itsContent
to some string:<Button Content="Click me" Margin...