-
Book Overview & Buying
-
Table Of Contents
Windows Presentation Foundation 4.5 Cookbook
By :
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.
Make sure Visual Studio is up and running.
We'll create several buttons (which are ContentControls) 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 root Grid to a StackPanel.
Add a Button to the StackPanel and set its Content to some string:
<Button Content="Click me" Margin...