在带有地址栏的 WPF 表单中嵌入 Web 浏览器 +按钮
我想在 WPF 应用程序中嵌入 Web 浏览器。浏览器应该看起来像一个普通的浏览器,有地址栏、后退和前进按钮以及状态栏。有没有一种方法可以轻松地用 XAML 编写,将地址直接数据绑定到文本框,将事件从按钮直接路由到 Web 浏览器对象,然后启用返回?
I wouldlike to embed a webbrowser in a WPF application. The browser should look like a normal browser, with address bar, back and forward button and status bar. Is there a way how that could easily written in XAML, with a direct databinding of the address to a textbox, with a direct routing of events from the buttons to the webbrowser object, and the enabling back?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么不呢?
此处和这里上传了我们应用程序的一些屏幕截图,该应用程序内部有 WebModule,并且能够像浏览器一样工作。
在我们的实现中,我们使用 Windows Forms WebBrowser 控件作为浏览器引擎,使用 MVVM 作为通信模式。模型具有引发适当事件的导航命令(前进、后退……)。 View 正在处理此事件并将请求的操作委托给内部 WebBrowser 组件。此外,视图还处理 WebBrowser 的事件(NewWindow、DocumentCompleted、Navigating、Naviated)并设置模型的状态。
模型和视图总共包含大约 500 行代码(我认为这不是很多,是吗?)。
当然,我应该提到,由于使用 IE 引擎,该浏览器在复杂的网站上可能会出现一些问题。
PS 我们没有使用 System.Windows.Controls.WebBrowser 因为它不提供对 NewWindow 事件的访问。
PPS 我已经从我们的 WPF 应用程序中的浏览器发布了这个答案。祝你好运!
Why not?
Here and here are uploaded some screenshots from our application which has WebModule inside and is able to work like browser.
In our implementation we used Windows Forms WebBrowser control as browser engine and MVVM as communication pattern. Model has navigation commands (forward, back, ...) that raise proper events. View is handling this events and delegate requested actions to inner WebBrowser component. Additionally view is handling WebBrowser's events (NewWindow, DocumentCompleted, Navigating, Navigated) and setting up model's state.
Model and view together contain about 500 lines of code (I don't think it's very much, do you?).
Of course, I should mention, that due to using IE engine this browser could have some problems on complicated web-sites.
P.S. We didn't use System.Windows.Controls.WebBrowser because it does not provide access to NewWindow event.
P.P.S. I've posted this answer from browser in our WPF application. Good luck!