tags:

views:

142

answers:

3

The Webbrowser in WPF can't display page unless mouse moving on.

This bug can't reproduce in my demo project, and I don't know how to fix it. I tried:

  • call WindowsFormsHost.UpdateLayout. (Failed)
  • call WindowsFormsHost's child, a WebBrowser control. call WebBrowser.Update or WebBrowser.Refresh. (Failed)
  • call WindowsFormsHost.InvalidateVisual() (Failed)

Is there other solution?


I even simulated mouse moving on like this:


AutomationElement element = AutomationElement.FromHandle(winAdHoster.Handle);
ATGTestInput.Input.MoveToAndClick(element);

this failed again.

A: 

Hi Cooper,

I have tree questions:

  • Does this happens after reboot?
  • Do you have AllowsTransparency="True" for the main window?
  • What OS do you have?
Anvaka
Does this happens after reboot? (YES, ALWAYS)Do you have AllowsTransparency="True" for the main window? (YES, BUT WebBrowser on other window, because WebBrowser control will always disapperence on a transparency='true' window)What OS do you have? (XP and Win7)
Cooper.Wu
A: 

In order to simulate actual mouse events, you can use following function throgh PInvoke, its system api to simulate mouse events this will work better then AutomationElement.

SendInput

Akash Kava
A: 

I finally fixed this bug via:

  1. moved init WebBrowser code to a method, which is the last method in Window_Loaded event.
  2. using BeginInvoke and Thread.Sleep(500) before init WebBrowsers.

We tested it on WinXp and Win7, it works well.

Cooper.Wu