WPF WebBrowser (3.5 SP1) Always on top - 在 WPF 中显示 HTML 的其他建议 [英] WPF WebBrowser (3.5 SP1) Always on top - other suggestion to display HTML in WPF

查看:17
本文介绍了WPF WebBrowser (3.5 SP1) Always on top - 在 WPF 中显示 HTML 的其他建议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在拼命寻找一种在 WPF 应用程序中显示 HTML 的简单方法.有一些选择:
1) 使用 WPF WebBrowser 控件
2)使用框架控件
3) 使用第三方控件

I've been desperately looking for an easy way to display HTML in a WPF-application. There are some options:
1) use the WPF WebBrowser Control
2) use the Frame Control
3) use a third-party control

但是,我遇到了以下问题:1) WPF WebBrowser Control 不是真正的 WPF(它是 WPF 中包装的 Winforms 控件).我找到了一种为此创建包装器的方法,并使用 DependencyProperties 导航到具有绑定和属性更改的 HTML 文本.这样做的问题是,如果您在 WPF 滚动查看器中放置一个 Winforms 控件,它不尊重 z-index,这意味着该 Winform 始终位于其他 WPF 控件之上.这很烦人,我试图通过创建一个承载 ElemenHost 等的 WindowsFormsHost 来解决这个问题,但这显然完全破坏了我的绑定.

but, i've ran into the following problems: 1) the WPF WebBrowser Control is not real WPF (it is a Winforms control wrapped in WPF). I have found a way to create a wrapper for this and use DependencyProperties to navigate to HTML text with bindings and propertychanged. The problem with this is, if you put a Winforms control in WPF scrollviewer, it doesnt respect z-index, meaning the winform is always on top of other WPF control. This is very annoying, and I have tried to work around it by creating a WindowsFormsHost that hosts an ElemenHost etc.. but this completely breaks my binding obviously.

2) Frame Control 在显示 HTML 内容时也有同样的问题.不是一个选项.

2) Frame Control has the same problems with displaying if it shows HTML content. Not an option.

3) 我还没有找到 WPF 的原生 HTML 显示.所有选项都是winform,并且存在上述问题.

3) I haven't found a native HTML-display for WPF. All options are winforms, and with the above mentioned problems.

我目前唯一的出路是使用微软有问题的 HtmlToXamlConverter,它有时会崩溃.(MSDN)

the only way out I have at the moment is using Microsoft's buggy HtmlToXamlConverter, which crashes hard sometimes. (MSDN)

是否有人对如何在 WPF 中显示 HTLM 而没有这些问题有任何其他建议?

Does anybody have any other suggestions on how to display HTLM in WPF, without these issues?

抱歉问了这么长的问题,希望有人知道我在说什么...

sorry for the long question, hope anyone knows what i'm talking about...

推荐答案

如果您不能使用 WebBrowser,最好的办法是将您的 HTML 内容重写为 FlowDocument(如果您使用的是静态 HTML 内容).

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).

否则,正如您所提到的,您必须对 WebBrowser 进行特殊处理,您是对的,它不像真正的"WPF 控件.您可能应该创建一个可以绑定到的 ViewModel 对象,该对象代表 WebBrowser 控件,您可以在其中将所有丑陋的非绑定代码隐藏在一个地方,然后再也不打开它:)

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 :)

这篇关于WPF WebBrowser (3.5 SP1) Always on top - 在 WPF 中显示 HTML 的其他建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆