[WPF Basics] [3] _ base element

Source: Internet
Author: User

Most classes in Windows Presentation Foundation (WPF) are derived from four classes, which are often called base element classes in SDK documents. These classes include uielement, frameworkelement, contentelement, and frameworkcontentelement. Dependencyobject is also a related class because it is a general base class of uielement and contentelement.

WPFBase element API in the class
Both uielement and contentelement are derived from dependencyobject, but the paths are slightly different. This level of splitting involves how to use the uielement or contentelement on the user interface and how they are used in the ApplicationProgramWhat role does it play. Uielement also has visual in its class hierarchy, which is supported by lower-level graphics exposed by Windows Presentation Foundation (WPF. Visual provides a rendering frame by defining an independent rectangular screen area. In fact, uielement is suitable for elements that support large data models. These elements are used for rendering and layout in areas that can be called rectangular screen areas. In this area, the content model is specially set to be more open, to allow different elements to be combined. Contentelement is not derived from visual; its model is composed of other objects (for example, a reader or viewer, used to interpret elements and generate a complete visual for Windows Presentation Foundation (WPF) to use contentelement. Some uielement classes can be used as content hosts: they provide the host and rendering for one or more contentelement classes (such as documentviewer. Contentelement is used as the base class for the following elements: it has a small object model and is mostly used to address the text, information, or document content that may host in the uielement.

Framework-level and core-level
Uielement is used as the base class of frameworkelement, and contentelement is used as the base class of frameworkcontentelement. The reason for this next level of classes is that they must support the WPF core level separated from the WPF framework level. This separation also exists in how APIs are divided between presentationcore and presentationframework assembly. The WPF framework provides a more complete solution for basic applications, including the implementation of the layout manager for representation. The WPF core level provides a way to make full use of WPF without additional assembly overhead. For most typical application development solutions, the differences between these levels have little impact, and the wpf api should generally be considered as a whole, there is no need to worry about the difference between the WPF framework level and the WPF core level. If your application is designed to replace a large number of WPF framework-level functions, for example, if your overall solution already has its own user interface (UI) combination and layout implementation, you may need to know the differences between levels.

Select which element to derive from
The most practical way to create a custom class for extended WPF is to derive from a WPF class, so that you can obtain as many functions as possible through the existing class hierarchy. This section lists the features that come with the three most important element classes to help you decide which class to derive from.

If you want to implement controls (which is indeed one of the more common reasons for deriving from the WPF class), you may need to derive from the following classes: the actual control or control family base class, or at least the control base class.

If you do not create a control and need to derive from a class with a higher level in the hierarchy, you can refer to the following sections to learn what features each base element class defines.

If you create a class derived from dependencyobject, It inherits the following functions:

Getvalue and setvalue support and general attribute system support.

The ability to use dependency attributes and additional attributes implemented as dependency attributes.

If you create a class derived from uielement, in addition to inheriting the functions provided by dependencyobject, it also inherits the following functions:

Basic Support for animation property values.

Supports basic input events and commands.

A virtual method that can be rewritten to provide information for the layout system.

If you create a class derived from frameworkelement, You can inherit the functions provided by uielement and the following functions:

Supports style settings and demonstration panels.

Supports data binding.

Supports dynamic resource reference.

Support for attributes inheritance and other labels in metadata that help report attributes to framework services (such as data binding, style or layout framework implementation.

The concept of the logical tree.

Support for the actual WPF framework-level implementation of the layout system, including onpropertychanged rewriting (this rewrite can detect attribute changes that affect the layout ).

If you create a class derived from contentelement, in addition to inheriting the functions provided by dependencyobject, it also inherits the following functions:

Animation support.

Supports basic input events and commands.

If you create a class derived from frameworkcontentelement, in addition to inheriting the functions provided by contentelement, you can also obtain the following functions:

Supports style settings and demonstration panels.

Supports data binding.

Supports dynamic resource reference.

Support for property value inheritance and other flags in metadata that help report property conditions (such as data binding, style, or Layout Framework Implementation) to Framework Services.

You do not have the permission to modify the layout system (such as arrangeoverride. The layout system is only available on frameworkelement. However, you will inherit the onpropertychanged override (you can detect attribute changes that affect the layout and report these changes to any content host ).

The content models of various types are recorded. If you want to find a suitable class to derive from the class, its content model is a possible factor to consider.

Other base classes

Dispatcherobject
Dispatcherobject supports the WPF thread model and allows all objects created for the WPF application to be associated with dispatcher. Even if you do not derive from uielement, dependencyobject, or visual, you should also consider deriving from dispatcherobject to obtain support for this thread model.

Visual
Visual Representation is usually required for Two-Dimensional Objects in areas with approximate rectangles. The actual rendering of visual occurs in other classes (not independent), but the visual class provides a known type used for presentation at various levels. Visual implements a hit test, but it does not publicly report events that hit the test results (all of which are in uielement ).

Freezable
Freezable simulates the immutability of a variable object by providing a copy for the object when the object is not changeable for performance reasons. The freezable type provides a general basis for certain graphic elements (such as geometric shapes, brushes, and animations. It is worth noting that freezable is not a visual. When freezable is applied to fill in the attribute values of another object, its attributes will become subattributes, and these subattributes may affect the rendering.

Animatable
Animatable is a freezable derived class. It adds the animation control layer and some utility members, so that the attributes of the current animation can be separated from those of the animation.

Control
Control is an ideal base class for object types called controls or components (depending on technology. Generally, the WPF control class is a class that directly represents the UI control or actively participates in the control combination. The main function of control is to templated controls.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.