tags:

views:

24

answers:

2

In order to create a screen shot, I am hiding a wpf window. The code looks like that.

      Hide();
      var fullScreenshot = _cropper.TakeFullScreenshot();
      Show();

Sometimes the Application is not hidden when the screen shot is taken. How can I can I identify, that the window is completely hidden?

A: 

Currently I am trying out this solution:

public void Foo()
{
    IsVisibleChanged += WhenVisibiltyChangend_TakeScreenshot_and_OpenCreateTicketDialog;
    Hide();
}}

void WhenVisibiltyChangend(object sender, DependencyPropertyChangedEventArgs e)
{
    if ((bool)e.NewValue == false) { 
        var fullScreenshot = _cropper.TakeFullScreenshot();
        Show();
    }
}

I hope this is the correct answer, but I have to do some additional tests.

Robert
+1  A: 

I don't know how the screenshot is taken but I suspect that the UI-Thread has not removed all the content and therefore the TakeFullScreenshot sees rests of your app.

I would try to wait until your app has done all necessary ui-work and then trigger the TakeFullScreenshot-operation.

Trigger the ScreenShot-Operation with the Dispatcher:

Hide();
Dispatcher.BeginInvoke(new Action(delegate { 
    fullScreenshot = _cropper.TakeFullScreenshot(); 
    Show();
    }), System.Windows.Threading.DispatcherPriority.ContextIdle, null);
HCL
I cant see how to do this async improves the situation, since the method is executed immediately? The question is, how to make sure that the UI thread has removed all the content.
Robert
@Robert: The given code executes the take-screenshot-operation not async. It will executed in the same thread as the BeginInvoke has been called. However it will executed only after the App has done all important work. This is specified by the DispatcherPriority-value (I took ContextIdle, I think this should do for sure, but maybe is a little overkill).
HCL