WtFudgE WtFudgE - 7 days ago 7
C# Question

NavigateToString not working on startup

I have this simple code:

public MainWindow()
{
InitializeComponent();
wbInhoudstafel.NavigateToString("<html><body><h1>test</h1></body></html>");
}


It used to work, but for some reason it doesn't work anymore :( Is there an option that could modify it's behavior?

The thing is, if I trigger an event in my application where I set the exact same string to the webbrowser element. It works..

And if I use .Navigate("http://www.google.com") after initialize it also works... Really don't get why it suddenly stopped working :s

Answer

I think you need to wait until the WebBrowser has finished loading.

private void wbInhoudstafel_Loaded(object sender, EventArgs e)
{
    wbInhoudstafel.NavigateToString("<html><body><h1>test</h1></body></html>");
}