Some time back I got a question about capturing the contents of a frame and it seemed easy, but every time I tried capturing the frame i was getting a blank image. The trick here is that the frame loads the content asynchronously - the simplest thing to do is wait for some time :) ...
The frame is an HwndHost that hosts an ActiveX control to load the web content. So the first thing to do is get hold of the HwndHost and then wait for a few seconds and you have it..
for (Visual v = TheFrame; v != null; v = VisualTreeHelper.GetChild(v, 0) as Visual)
hwndHost = v as HwndHost;
if (hwndHost != null)
Now create a DispatcherTimer and wait till it triggers
DispatcherTimer timer = new DispatcherTimer();
timer.Tick += TheFrameAfterLoaded;
timer.Interval = TimeSpan.FromSeconds(5);
timer.Tag = hwndHost;
void TheFrameAfterLoaded(object sender, EventArgs e)
DispatcherTimer timer = sender as DispatcherTimer;
HwndHost hwndHost = (HwndHost) timer.Tag;
Image image = new Image();
image.Source = new DrawingImage(VisualTreeHelper.GetDrawing(TheFrame));
Project is attached :)
Lester, this does not work for me w/ frame ... [get empty capture].. works for me with other controls..
Running on Vista ...
Did you try subscribing to the ContentRendered event instead?
its likely that the content is not getting rendered... you could possibly increase the time.