我正在使用雙贏的WebControl(也嘗試了內置的WPF瀏覽器),它的內容是簡單的HTML和JavaScript文件,它們被定義爲嵌入式資源。Web瀏覽器和嵌入式資源
對於我的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;
}
Web內容:
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和沒有辦法要知道從嵌入式資源中獲取它,除非你明確地設置它們。 [檢查此](http://stackoverflow.com/questions/9934357/how-to-load-html-javascript-from-embedded-resource-into-winform-web-browser) –