【问题标题】:How to display an html content inside wpf?如何在 wpf 中显示 html 内容?
【发布时间】:2017-10-06 04:38:53
【问题描述】:

我需要在 WPF 中显示 HTML 内容。 这是我的 XAML 代码:

<WebBrowser Source="Views/Sample.html"></WebBrowser>

谢谢。

【问题讨论】:

标签: wpf xaml


【解决方案1】:

您好,我正在更好地更新答案

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();

        var exePath = AppDomain.CurrentDomain.BaseDirectory;
        var pagesFolder = Directory.GetParent(exePath).Parent.Parent;
        string homePageFullPath = pagesFolder.FullName + "\\Pages\\Home.html";
        WebBrowser1.Source = new Uri(homePageFullPath);
    }

}

您需要在 wpf exe 所在的 bin 文件夹中有 home.html。您可以将“复制到输出目录”设置为“始终复制”

上面的对我有用。

如果文件在不同的文件夹中,请提供绝对路径

【讨论】:

  • 你能告诉我错误,你的代码和文件路径吗?
  • 正在显示,请确保路径或互联网地址正确。
  • 恐怕我无法帮助您,除非您这里有一些代码。您还可以将其中一个 html 复制到 bin 文件夹并通过替换名称来尝试我的代码吗?即 WebBrowser1.Source = new Uri(new System.IO.FileInfo("Home.html").FullName);
  • sample.Source = new Uri(new System.IO.FileInfo("View.html").FullName);这是我的代码
  • 好的,你能把 View.html 放到 bin\Debug 文件夹里试试吗?
猜你喜欢
  • 1970-01-01
  • 2013-02-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多