【发布时间】:2016-03-03 23:35:08
【问题描述】:
我正在使用win-forms WebControl(也尝试了内置的WPF浏览器),它的内容是定义为嵌入式资源的简单html和JavaScript文件。
对于我的 POC,所有文件都必须嵌入。
XAML:
<Window x:Class="WebPOC.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:forms="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
Title="MainWindow" Height="350" Width="525">
<Grid>
<WindowsFormsHost>
<forms:WebBrowser x:Name="WebBrowser"/>
</WindowsFormsHost>
</Grid>
代码隐藏:
public MainWindow()
{
InitializeComponent();
var stream = Assembly.GetEntryAssembly().GetManifestResourceStream("WebPOC.www.index.html");
WebBrowser.DocumentStream = stream;
}
网页内容:
alert("test");
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<script src="js/test.js"></script>
<title></title>
</head>
<body>
<p>test</p>
</body>
</html>
由于某种原因,链接的 JavaScript 文件出错:
有什么想法吗?
【问题讨论】:
-
它在错误的地方寻找嵌入的 js,除非您明确设置它们,否则它无法知道从嵌入资源中获取它。 check this
标签: c# wpf webbrowser-control