Windows Presentation Foundation: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
Giamak (discussione | contributi)
Riga 18:
 
The UI elements of a WPF application are maintained as a class of Visual objects. Visual objects provide a managed interface to a composition tree which is maintained by Media Integration Layer (MIL). Each element of WPF creates and adds one or more composition nodes to the tree. The composition nodes contain rendering instructions, such as clipping and transformation instructions, along with other visual attributes. Thus the entire application is represented as a collection of composition nodes, which are stored in a buffer in the system memory. Periodically, MIL walks the tree and executes the rendering instructions in each node, thus compositing each element on to a DirectX surface, which is then rendered on screen. MIL uses the painter's algorithm, where all the components are rendered from back of the screen to the front, which allows complex effects like transparencies to be easily achieved. This rendering process is hardware accelerated using the GPU.[6] The composition tree is cached by MIL, creating a retained mode graphics, so that any changes to the composition tree needs only to be incrementally communicated to MIL. This also frees the applications of managing repainting the screen, MIL can do that itself as it has all the information necessary. Animations can be implemented as time-triggered changes to the composition tree. On the user visible side, animations are specified declaratively, by setting some animation effect to some element via a property and specifying the duration. The code-behind updates the specific nodes of the tree, via Visual objects, to represent both the intermediate states at specified time intervals as well as the final state of the element. MIL will render the changes to the element automatically.
 
All WPF applications start with two threads: one for managing the UI and another background thread for handling rendering and repainting.[7] Rendering and repainting is managed by WPF itself, without any developer intervention. The UI thread houses the Dispatcher (via an instance of DispatcherObject), which maintains a queue of UI operations that need to be performed (as a tree of Visual objects), sorted by priority. UI events, including changing a property that affects the layout, and user interaction events raised are queued up in the dispatcher, which invokes the handlers for the events. Microsoft recommends that the event handlers only update the properties to reflect new content for application responsiveness; the new content be generated or retrieved in a background thread.[7] The render thread picks up a copy of the visual tree and walks the tree calculating which components will be visible and renders them to Direct3D surfaces. The render thread also caches the visual tree, so only changes to the tree need to be communicated, which will result in updating only the changed pixels. WPF supports an extensible layout model. Layout is divided into two phases: Measure and Arrange. The Measure phase recursively calls all elements and determine the size they will take. In the Arrange phase, the child elements are recursively arranged by their parents, invoking the layout algorithm of the layout module in use.[6][8]
 
-->
 
Tutte le applicazioni WPF sono composte da 2 threads: il thread per gestire la UI e l'altro thread detto render thread che in maniera nascosta gestisce le funzioni di rendering e repainting. Perciò rendering e repainting sono gestite da WPF stesso, senza intervento dello sviluppatore. Il thread per la UI ospita il Dispatcher(attraverso un'istanza dell'oggetto DispatcherObject), il quale mantiene una coda di operazioni che necessitano di essere eseguite sulla UI(come un albero fatto di oggetti Visual, detto albero visuale) ordinate per priorità. Gli eventi della UI, compreso il cambiamento di una proprietà che riguarda il layout, ed eventi causati dall'interazione dell'utente sono accodati nel dispatcher, il quale invoca i gestori degli eventi. Microsoft raccomanda che i gestori degli eventi solo aggiornino le proprietà per riflettere il nuovo contenuto come risposta; il nuovo contenuto sarà generato o recuperato dal render thread. Il render thread prende una copia dell'albero visuale e attraversa l'albero calcolando quali componenti saranno visibili e renderizzandoli come superfici Direct3D. Il render threads anche salva in una cache l'albero visuale, così solo i cambiamenti all'albero devono essere comunicati, e perciò soltando i pixel cambiati risulteranno aggiornati. WPF supporta un modello di layout estendibile. Il layout è diviso in due fasi che svolgono le funzioni di misurare ed adattare. Nella fase di misura ricorsivamente vengono chiamati tutti gli elementi e determinato lo spazio che essi prendono. Nella fase di adattazione, gli elementi figli vengono ricorsivamente adattati nello spazio dei loro genitori, invocando l'algoritmo di layout del modulo in uso.
{{portale|Microsoft}}
[[Categoria:Microsoft Windows]]