0

我正在处理版本历史对话框,并创建了一个示例来测试它。但是,该示例似乎找不到 HTML 文件:

        var dlg = new VersionHistoryDialog();
        var uri = new Uri(@"pack://application:,,,/VersionHistory.html", UriKind.Absolute);
        var source = Application.GetResourceStream(uri).Stream; // This line throws the error
        dlg.Stream = source;
        var result = dlg.ShowDialog();
        label1.Content = result;

上面代码中的那一行引发了这个错误:

System.IO.IOException was unhandled
  Message=Cannot locate resource 'versionhistory.html'.
  Source=PresentationFramework
  StackTrace:
       at MS.Internal.AppModel.ResourcePart.GetStreamCore(FileMode mode, FileAccess access)
       at System.IO.Packaging.PackagePart.GetStream(FileMode mode, FileAccess access)
       at System.IO.Packaging.PackagePart.GetStream()
       at System.Windows.Application.GetResourceStream(Uri uriResource)
    ....

所以....我该怎么办?该文件名为“ ”,并且它与请求它VersionHistory.html的文件位于同一文件夹(“视图”)中。xaml.cs

4

1 回答 1

3

您需要包括资源的程序集和路径:

例如:

Application.GetResourceStream(new Uri("/SilverlightApplication;component/EmbeddedInApplicationAssembly.png", UriKind.Relative)))

使用包和您的示例,您可以指定:

Application.GetResourceStream(new Uri("pack://application:,,,/View/versionhistory.html"))

以下也应该有效:

Application.GetResourceStream(new Uri("/XYZ;component/View/versionhistory.html", UriKind.Relative)))

有关详细信息,请参阅http://msdn.microsoft.com/en-us/library/ms596994(VS.95).aspxhttp://msdn.microsoft.com/en-us/library/aa970069.aspx

于 2010-10-22T12:45:20.897 回答