I have a strange problem. I have tabcontrol and 3 tabs. On each tab, I got a web browser control on it. They all go to the site. But it only works if you are really looking at a web browser control. Therefore, by minimizing the taskbar or systray, do not go to the website.
Why? How can I change this behavior?
[EDIT]
It is like I'm running an application. Once he has received a “focus” or “look,” this does not happen anymore.
Additional navigation information comes from a stream other than the UI stream. [/ EDIT]
[3rd EDIT]
Here is an example:
XAML Code:
<Window x:Class="WPFWebbrowserFocusTest.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="453" Width="755"> <Grid> <TabControl Height="390" HorizontalAlignment="Left" Margin="12,12,0,0" Name="tabControl1" VerticalAlignment="Top" Width="709"> <TabItem Header="tabItem1" Name="tabItem1"> <Grid> <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="18,17,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" /> </Grid> </TabItem> <TabItem Header="tabItem2" Name="tabItem2"> <Grid> <WebBrowser Height="352" HorizontalAlignment="Left" Margin="0,6,0,0" Name="webBrowser1" VerticalAlignment="Top" Width="693" Navigated="webbrowser_Navigated" LoadCompleted="webbrowser_LoadCompleted" /> </Grid> </TabItem> <TabItem Header="tabItem3" Name="tabItem3"> <Grid> <WebBrowser Height="346" HorizontalAlignment="Left" Margin="6,6,0,0" Name="webBrowser2" VerticalAlignment="Top" Width="687" Navigated="webbrowser_Navigated" LoadCompleted="webbrowser_LoadCompleted" /> </Grid> </TabItem> <TabItem Header="tabItem4" Name="tabItem4"> <Grid> <WebBrowser Height="346" HorizontalAlignment="Left" Margin="10,10,0,0" Name="webBrowser3" VerticalAlignment="Top" Width="687" Navigated="webbrowser_Navigated" LoadCompleted="webbrowser_LoadCompleted" /> </Grid> </TabItem> <TabItem Header="tabItem5" Name="tabItem5"> <Grid> <WebBrowser Height="346" HorizontalAlignment="Left" Margin="10,10,0,0" Name="webBrowser4" VerticalAlignment="Top" Width="687" Navigated="webbrowser_Navigated" LoadCompleted="webbrowser_LoadCompleted" /> </Grid> </TabItem> </TabControl> </Grid>
Here is the code behind the file:
public MainWindow() { InitializeComponent(); } private void webbrowser_Navigated(object sender, NavigationEventArgs e) { this.SuppressScriptErrors((WebBrowser)sender, true); } private void webbrowser_LoadCompleted(object sender, NavigationEventArgs e) { WebBrowser wb = (WebBrowser)sender; if (e.Uri.AbsoluteUri != wb.Source.AbsoluteUri) return; } public void SuppressScriptErrors(System.Windows.Controls.WebBrowser wb, bool Hide) { FieldInfo fi = typeof(System.Windows.Controls.WebBrowser).GetField( "_axIWebBrowser2", BindingFlags.Instance | BindingFlags.NonPublic); if (fi != null) { object browser = fi.GetValue(wb); if (browser != null) { browser.GetType().InvokeMember("Silent", BindingFlags.SetProperty, null, browser, new object[] { Hide }); } } } private void button1_Click(object sender, RoutedEventArgs e) { this.webBrowser1.Navigate("http://www.google.com"); this.webBrowser2.Navigate("http://www.google.com"); this.webBrowser3.Navigate("http://www.google.com"); this.webBrowser4.Navigate("http://www.google.com"); }
How to reproduce:
Place a breakpoint inside webbrowser_LoadCompleted . Then click the button located on the first tab of the tabcontrol.
Do not go to the next tab, wait a few seconds, for example 15 or so.
Then go to tabitem2 or 3/4/5. You will see that the page has just loaded and the webbrowser_LoadCompleted event webbrowser_LoadCompleted been fired.