Reputation: 5228
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
Upvotes: 1
Views: 4193
Reputation: 891
Hmm, in my case WebBrowser_Loaded event gets never called. I am talking about System.Windows.Controls.WebBrowser which is what this question is about.
Upvotes: 0
Reputation: 35400
If the accepted answer doesn't work for anyone else too, try using Dispatcher.BeginInvoke()
inside the Loaded
event handler:
private void WB_Loaded(object sender, EventArgs e)
{
Dispatcher.BeginInvoke(() =>
{
WB.NavigateToString("<html><body>This works!</body></html>");
});
}
Upvotes: 0
Reputation: 292465
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>");
}
Upvotes: 4