Skip to Main Content
Programming WPF, 2nd Edition
book

Programming WPF, 2nd Edition

by Chris Sells, Ian Griffiths
August 2007
Intermediate to advanced content levelIntermediate to advanced
864 pages
25h 52m
English
O'Reilly Media, Inc.
Content preview from Programming WPF, 2nd Edition

ContentControl

System.Object
    System.Windows.Threading.DispatcherObject
        System.Windows.DependencyObject
            System.Windows.Media.Visual
                System.Windows.UIElement
                    System.Windows.FrameworkElement
                        System.Windows.Controls.Control
                            System.Windows.Controls.ContentControl

ContentControl is a specialization of Control. It's the base class for any control that can host a single piece of content, which goes in the Content property. The content can be plain text or a tree of user interface elements (e.g., a nested control, or a panel containing several child items). The content can also be any .NET object, in which case WPF will attempt to display it using a data template: if you set the ContentTemplate or ContentTemplateSelector property, WPF will use the template you supply, but otherwise it will attempt to locate a template automatically. If it can't find a template, it will display the value returned by the object's ToString method. We describe data templates in Chapter 6.

Some controls derive from ContentControl in order to offer a caption. For example, the various button types (e.g., Button, CheckBox, RadioButton; see Chapter 5 for details) typically contain either text or graphics. By deriving from ContentControl, these buttons are able to host any mixture of text and graphics.

An alternative reason to derive from ContentControl is to offer a service wrapped around arbitrary content. For example, ScrollViewer can host any content, providing scroll bars for when the content is larger than the ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Programming C#, 4th Edition

Programming C#, 4th Edition

Jesse Liberty
Programming C# 10

Programming C# 10

Ian Griffiths

Publisher Resources

ISBN: 9780596510374Supplemental ContentErrata Page