Wpf Webbrowser (3.5 Sp1) Always on Top - Other Suggestion to Display HTML in Wpf

WPF WebBrowser (3.5 SP1) Always on top - other suggestion to display HTML in WPF

If you can't use WebBrowser, your best bet is to probably rewrite your HTML content into a FlowDocument (if you're using static HTML content).

Otherwise, as you mention, you kind of have to special-case WebBrowser, you're right that it doesn't act like a "real" WPF control. You should probably create a ViewModel object that you can bind to that represents the WebBrowser control where you can hide all of the ugly non-binding code in one place, then never open it again :)

Is there a way to render WPF controls on top of the wpf WebBrowser control?

Embedded WebBrowsers suck, unfortunately. If you're displaying actual, real, dynamic web content in your WebBrowser, you have to go through the pain of linking another Window to your hosted WebBrowser's window, and handling moving/resizing/et al yourself. I haven't seen another way that works.

If you're displaying static content (or content from a source that you can control or influence), you might consider displaying, say, RTF docs in a DocumentViewer instead, which doesn't have the icky airspace issues of the WebBrowser control.

WPF WebBrowser disable clicking & typing

Three events and Boolean did it for me.

    bool BrowserIsLoaded = false;

private void Browser_LoadCompleted(object sender, NavigationEventArgs e)
{
BrowserIsLoaded = true;
}

private void Browser_Navigating(object sender, NavigatingCancelEventArgs e)
{
if(BrowserIsLoaded)
e.Cancel = true;
}

private void Browser_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (BrowserIsLoaded)
e.Handled = true;
}

When the browser has finished loading it triggers the LoadCompleted event. Set a Boolean then check that when trying to navigate to a new page when they try to type in a box.

If you don't want to use your own Boolean (I used it for other things so it made sense to me) you can just ask the browser if it's loaded when ever you need it:

    private void Browser_Navigating(object sender, NavigatingCancelEventArgs e)
{
WebBrowser wb = (WebBrowser)sender;
if(wb.IsLoaded)
{
e.Cancel = true;
}
}

Is it possible to overlap WPF WebBrowser with other UIElement?

No, the WPF Webbrowser is just the standard browser control in a WPF wrapper. It is not native WPF and therefore does not respect the ZOrder of WPF apps.

Prevent scrollbars with WPF WebBrowser displaying content

I guess you can get width and height of the webbrowser component content through its Document property which should be of mshtml.HTMLDocument type. I believe you should be able to use body or documentElement properties to get needed sizes; smth like this:

mshtml.HTMLDocument htmlDoc = webBrowser.Document as mshtml.HTMLDocument;
if (htmlDoc != null && htmlDoc.body != null)
{
mshtml.IHTMLElement2 body = (mshtml.IHTMLElement2)htmlDoc.body;
webBrowser.Width = body.scrollWidth;
webBrowser.Height = body.scrollHeight;
}

hope this helps, regards



Related Topics



Leave a reply



Submit