[I cannot make up my mind how to best start this post. Instead of delaying it for another month, I opted to post it anyway. <warning>Take it with a pound of salt, I may be terribly wrong in this article.</warning>]
A few pictures from MSDN should be the best start. They show the interaction between Win32 provided API, DirectX and WPF.
- How WPF leverages Windows Platform

- The Visual tree

- How WPF draws your application.

These articles are mainly focused on graphics implementation in PresentationFramework, PresentationCore and WindowsBase. The unmanaged part will discuss milcore.dll, dwm.exe, dwmapi.exe, user32.dll’s redirection APIs.
To dig into all of this, we need a working application. This code will be used through out this post.
using System;
using System.Windows;
namespace WPF
{
class App : Window
{
[STAThread]
public static void Main( )
{
( new Application( ) ).Run( new App( ) );
}
protected override void OnRender( System.Windows.Media.DrawingContext drawingContext )
{
System.Diagnostics.StackTrace st = new System.Diagnostics.StackTrace( System.Threading.Thread.CurrentThread , true );
Console.WriteLine( st.ToString( ) );
base.OnRender( drawingContext );
}
}
}
As the name suggest, OnRender is the only method called to do all the drawing. A debug tip shows that it is really an object of type System.Windows.Media.VisualDrawingContext.

Fire up Reflector and have a look at this class:

As we see VisualDrawingContext does not contain many things. _ownerVisual is any Visual having an associated VisualDrawingContext and CloseCore just calls RenderClose on the contained Visual. DrawingContext is the base class which defines the characteristics of what can be drawn and how. DispatcherObject is of no concern here, but in the going, it is essentially a wrapper around System.Threading.Thread and provides some services which check whether, through VerifyAccess and CheckAccess, the caller is on same thread as UI thread or not.
Furthermore, DrawingContext is abstract, therefore, an instance can never be created. RenderDataDrawingContext has an internal constructor. Same goes for its instance too. A transitive closure with the help of Reflector shows that there is no other way to create an instance publically without going through RenderOpen, which returns an instance of VisualDrawingContext.
You may have noticed by now that I skipped RenderDataDrawingContext’s description. Well that’s the topic for next post.