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

UserControl

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
                                System.Windows.Controls.UserControl

The UserControl class is designed to provide an easy way to build a custom control using the same techniques and tools you would use to create a window: the appearance is defined with markup, and the behavior is defined in a code-behind file. This provides an easy way to build a reusable chunk of user interface. It also offers a useful tool for managing complexity: if a window has become too complex, it may be easier to split its content into a set of user controls, allowing developers to work on individual pieces independently.

UserControl is almost identical to its base class, ContentControl. It adjusts the default values for a few properties. For example, a UserControl disables keyboard focus and tab stop navigation for itself, although not for its content—the assumption is that a UserControl will typically contain focus targets such as text boxes and buttons, so the containing control itself will usually not need to act as a distinct focus target.

UserControl is not strictly necessary for building elements through markup, composition, and code behind. You can also use this style if you derive directly from ContentControl, or any other element that accepts one or more children, such as Decorator ...

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