0

I need to display HTML content inside the WPF. Here is my XAML code:

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

Thanks.

Manfred Radlwimmer
  • 13,257
  • 13
  • 53
  • 62
Jithu
  • 21
  • 1
  • 3
  • You can use web browser control. Hope the below one can help you [http://stackoverflow.com/questions/5362591/how-to-display-the-string-html-contents-into-webbrowser-control](http://stackoverflow.com/questions/5362591/how-to-display-the-string-html-contents-into-webbrowser-control) – Kiran B May 08 '17 at 08:41
  • No I need to add from a folder as source to web browser – Jithu May 08 '17 at 08:42
  • You can use a text reader and get the html from the file and append to the browser control – Kiran B May 08 '17 at 08:43
  • See this too [http://stackoverflow.com/questions/2585782/displaying-html-from-string-in-wpf-webbrowser-control](http://stackoverflow.com/questions/2585782/displaying-html-from-string-in-wpf-webbrowser-control) – Kiran B May 08 '17 at 08:50
  • 2
    `Thanks` is your XAML code ? – Jones Joseph May 08 '17 at 12:33
  • Possible duplicate of [Displaying html from string in WPF WebBrowser control](http://stackoverflow.com/questions/2585782/displaying-html-from-string-in-wpf-webbrowser-control) – Ankur Tripathi May 08 '17 at 13:20

1 Answers1

0

Hi I am updating the answer better

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

}

You need to have the home.html in the bin folder where the wpf exe is located. You can make the "Copy To Output Directory" as "Copy Always"

The above one is working for me.

If the file is in a different folder please have the absolute path

Kiran B
  • 683
  • 10
  • 21