0

我有一个带有 WebBrowser 控件的 WPF 项目。我想导航到项目中的 HTML 页面。当我构建我的项目时,我的 bin 文件夹中有一个名为 Rule1.html 的 HTML 文件。我尝试了以下方法:

 System.Uri uri = new Uri("Rule1.html");
 webb1.Navigate(uri);

我收到以下错误:

Cannot create instance of 'MainWindow' defined in assembly 'BB, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. Exception has been thrown by the target of an invocation.  Error in markup file 'MainWindow.xaml' Line 1 Position 9.

当我使用绝对 Uri 时,程序和控件工作正常,但我只想使用暂时存在于我的应用程序中的 html 页面。我怎样才能做到这一点?

4

2 回答 2

2

我不确定该 URI 创建语句是否有效,它似乎无法在我的机器上运行。

您必须为其指定路径。

Uri uri = new Uri(AppDomain.CurrentDomain.BaseDirectory + @"\Rule1.html");

AppDomain.CurrentDomain.BaseDirectory “获取程序集解析器用来探测程序集的基本目录。”

于 2013-09-17T13:25:28.467 回答
0

尝试这个:

System.Uri uri = new Uri("file://" + @"C:\Test\test.html", UriKind.Absolute);
webb1.Navigate(uri);
于 2013-09-17T14:02:18.067 回答