如何在wpf中显示html内容?

如何在wpf中显示html内容?,wpf,xaml,Wpf,Xaml,我需要在WPF中显示HTML内容。 以下是我的XAML代码: <WebBrowser Source="Views/Sample.html"></WebBrowser> 谢谢。嗨,我正在更新答案,以便更好地回答问题 public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); var exePath = A

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

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


谢谢。

嗨,我正在更新答案,以便更好地回答问题

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);
    }

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

上面的那个对我有用


如果文件位于其他文件夹中,请使用绝对路径

您可以使用web浏览器控件。希望下面的一个可以帮助您不,我需要从文件夹中添加源到web浏览器您可以使用文本阅读器从文件中获取html并附加到浏览器控件查看此内容
谢谢
是您的XAML代码吗?您能给我错误、代码和文件路径吗?正在显示,请确保路径或internet地址正确。我恐怕无法帮助您,除非您这里有一些代码。另外,请您将其中一个html复制到bin文件夹,并通过替换名称来尝试我的代码,好吗?ie WebBrowser1.Source=新Uri(new System.IO.FileInfo(“Home.html”).FullName);sample.Source=newURI(new System.IO.FileInfo(“View.html”).FullName);这是我的代码OK你能把View.html放在bin\Debug文件夹中试试吗?