Compartilhar via


Visão geral sobre elementos base

Uma alta porcentagem de classes em Windows Presentation Foundation (WPF) são derivados de quatro classes que são normalmente chamado na SDK documentação como as classes de elemento base. These classes are UIElement, FrameworkElement, ContentElement, and FrameworkContentElement. O DependencyObject classe também está relacionado, porque é uma classe base comum de ambos UIElement e ContentElement

Este tópico contém as seguintes seções.

  • Base Element APIs in WPF Classes
  • Choosing Which Element to Derive From
  • Other Base Classes
  • Tópicos relacionados

Base Element APIs in WPF Classes

Both UIElement and ContentElement are derived from DependencyObject, through somewhat different pathways. A divisão neste nível lida com como um UIElement ou ContentElement são usados em uma interface de usuário e o objetivo da qual eles servem em um aplicativo. UIElementtambém tem Visual em sua hierarquia de classe, que é uma classe que expõe a base de suporte a gráficos de nível inferior a Windows Presentation Foundation (WPF). VisualFornece uma estrutura de processamento por meio da definição de regiões da tela de retangular independentes. Na prática, UIElement é para elementos que oferecerá suporte a um modelo de objeto maior, destinam-se para processar e o layout em regiões que podem ser descritos como regiões de tela retangular, e onde o modelo de conteúdo é deliberadamente mais aberto, para permitir que diferentes combinações de elementos. ContentElementnão é derivada de Visual; seu modelo é que uma ContentElement deve ser consumido por algo, como um leitor ou viewer que poderia interpretar os elementos e produzir o completo Visual para Windows Presentation Foundation (WPF) para consumir. Certas UIElement classes devem ser hosts de conteúdo: eles fornecem a hospedagem e o processamento para um ou mais ContentElement classes (DocumentViewer é um exemplo de como uma classe). ContentElementé usado como classe base para elementos com um pouco menor modelos de objetos e que mais o texto, informações, de endereço ou o conteúdo do documento que pode ser hospedado dentro de um UIElement.

Framework-Level and Core-Level

UIElement serves as the base class for FrameworkElement, and ContentElement serves as the base class for FrameworkContentElement. The reason for this next level of classes is to support a WPF core level that is separate from a WPF framework level, with this division also existing in how the APIs are divided between the PresentationCore and PresentationFramework assemblies. The WPF framework level presents a more complete solution for basic application needs, including the implementation of the layout manager for presentation. The WPF core level provides a way to use much of WPF without taking the overhead of the additional assembly. The distinction between these levels very rarely matters for most typical application development scenarios, and in general you should think of the WPF APIs as a whole and not concern yourself with the difference between WPF framework level and WPF core level. You might need to know about the level distinctions if your application design chooses to replace substantial quantities of WPF framework level functionality, for instance if your overall solution already has its own implementations of user interface (UI) composition and layout.

Choosing Which Element to Derive From

The most practical way to create a custom class that extends WPF is by deriving from one of the WPF classes where you get as much as possible of your desired functionality through the existing class hierarchy. This section lists the functionality that comes with three of the most important element classes to help you decide which class to inherit from.

If you are implementing a control, which is really one of the more common reasons for deriving from a WPF class, you probably want to derive from a class that is a practical control, a control family base class, or at least from the Control base class. For some guidance and practical examples, see Visão geral sobre criação de controles.

If you are not creating a control and need to derive from a class that is higher in the hierarchy, the following sections are intended as a guide for what characteristics are defined in each base element class.

If you create a class that derives from DependencyObject, you inherit the following functionality:

  • GetValue and SetValue support, and general property system support.

  • Ability to use dependency properties and attached properties that are implemented as dependency properties.

If you create a class that derives from UIElement, you inherit the following functionality in addition to that provided by DependencyObject:

  • Basic support for animated property values. For more information, see Revisão de Animação.

  • Basic input event support, and commanding support. For more information, see Input Overview and Visão geral de Comando.

  • Virtual methods that can be overridden to provide information to a layout system.

If you create a class that derives from FrameworkElement, you inherit the following functionality in addition to that provided by UIElement:

If you create a class that derives from ContentElement, you inherit the following functionality in addition to that provided by DependencyObject:

If you create a class that derives from FrameworkContentElement, you get the following functionality in addition to that provided by ContentElement:

Content models are documented for a variety of classes. The content model for a class is one possible factor you should consider if you want to find an appropriate class to derive from. For more information, see Modelo de conteúdo WPF.

Other Base Classes

DispatcherObject

DispatcherObject provides support for the WPF threading model and enables all objects created for WPF applications to be associated with a Dispatcher. Mesmo se você não deriva de UIElement, DependencyObject, ou Visual, você deve considerar a derivação de DispatcherObject para obter esse suporte de modelo threading. For more information, see Modelo de Threading.

Visual

Visualimplementa o conceito de um objeto 2D, geralmente requer a apresentação visual em uma região de aproximadamente retangular. O processamento real de um Visual acontece em outras classes (não é autônomo), mas o Visual classe fornece um tipo conhecido que é usado pelos processos de processamento em vários níveis. Visualimplementa o teste de hit, mas ele não expõe eventos que o relatam de teste de hit positivos (esses são em UIElement). For more information, see Programação de Camada Visual.

Freezable

Freezable simulates immutability in a mutable object by providing the means to generate copies of the object when an immutable object is required or desired for performance reasons. The Freezable type provides a common basis for certain graphics elements such as geometries and brushes, as well as animations. Notably, a Freezable is not a Visual; it can hold properties that become subproperties when the Freezable is applied to fill a property value of another object, and those subproperties might affect rendering. For more information, see Visão geral sobre objetos Freezable.

Animatable

Animatable is a Freezable derived class that specifically adds the animation control layer and some utility members so that currently animated properties can be distinguished from nonanimated properties.

Control

Control is the intended base class for the type of object that is variously termed a control or component, depending on the technology. In general, WPF control classes are classes that either directly represent a UI control or participate closely in control composition. A principal funcionalidade que Control permite que é modelagem de controle.

Consulte também

Referência

Control

Conceitos

Visão geral sobre propriedades de dependência

Visão geral sobre criação de controles

Arquitetura WPF