Visual
System.Object
System.Windows.Threading.DispatcherObject
System.Windows.DependencyObject
System.Windows.Media.VisualThe 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.