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

Visual

System.Object
    System.Windows.Threading.DispatcherObject
        System.Windows.DependencyObject
            System.Windows.Media.Visual

The Visual class is the abstract base class of all 2D elements in the visual tree. It provides rendering services, as well as transformation and hit testing support.

This class is not an extensibility point—you cannot usefully derive your own classes from it, because all the rendering services it provides are defined by members marked as internal. You must inherit from UIElement if you wish to exploit the rendering services. However, it is important to be aware of Visual because it crops up in various APIs. For example, the VisualBrush, which we describe in Chapter 13, lets you create a brush that can paint using a copy of the appearance of any object derived from Visual.

Most types derived from Visual derive from UIElement, which we describe later. One useful exception is the DrawingVisual class. This provides a lightweight way of hosting a drawing. We describe drawings in Chapter 13.

WPF provides a class called VisualTreeHelper. This provides methods for navigating the visual tree. Surprisingly, these are not defined in terms of the Visual class. This is because 3D elements have an independent branch of the class hierarchy, but are still considered part of the visual tree. VisualTreeHelper therefore works with both Visual and Visual3D objects. We describe the VisualTreeHelper class in Chapter 9.

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