{"id":23173326,"url":"https://github.com/michaldivis/dark-html-viewer","last_synced_at":"2026-05-02T19:32:40.035Z","repository":{"id":37928455,"uuid":"366708734","full_name":"michaldivis/dark-html-viewer","owner":"michaldivis","description":"A simple HTML viewer control for WPF (using WebView2)","archived":false,"fork":false,"pushed_at":"2023-02-20T13:59:32.000Z","size":3328,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-11-27T09:20:28.663Z","etag":null,"topics":["html-viewer","webview2","wpf"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/michaldivis.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-05-12T12:31:35.000Z","updated_at":"2025-05-29T19:06:05.000Z","dependencies_parsed_at":"2024-12-18T05:12:04.482Z","dependency_job_id":"eec3487c-4c73-4065-acd6-3e054db78afc","html_url":"https://github.com/michaldivis/dark-html-viewer","commit_stats":null,"previous_names":["michaldivis/darkhtmlviewer"],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/michaldivis/dark-html-viewer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaldivis%2Fdark-html-viewer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaldivis%2Fdark-html-viewer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaldivis%2Fdark-html-viewer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaldivis%2Fdark-html-viewer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/michaldivis","download_url":"https://codeload.github.com/michaldivis/dark-html-viewer/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaldivis%2Fdark-html-viewer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32547645,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-02T19:18:06.202Z","status":"ssl_error","status_checked_at":"2026-05-02T19:16:21.335Z","response_time":132,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["html-viewer","webview2","wpf"],"created_at":"2024-12-18T05:11:49.808Z","updated_at":"2026-05-02T19:32:40.018Z","avatar_url":"https://github.com/michaldivis.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Dark HTML Viewer\n\nA WPF user control for displaying in memory HTML. The control stores the loaded HTML in temporary files and uses the [WebView2](https://docs.microsoft.com/en-us/microsoft-edge/webview2/) control to display them.\n\n## Nuget\n[![Nuget](https://img.shields.io/nuget/v/divis.darkhtmlviewer?label=Divis.DarkHtmlViewer)](https://www.nuget.org/packages/Divis.DarkHtmlViewer/)\n\n## Usage\n\n### Basics\nAdd the namespace to your XAML\n```XML\nxmlns:dhv=\"clr-namespace:DarkHtmlViewer;assembly=DarkHtmlViewer\"\n```\n\nAnd use the `HtmlViewer` control\n```XML\n\u003cdhv:HtmlViewer x:Name=\"htmlViewer\" /\u003e\n```\n\n### Commands \u0026 methods\n`LoadCommand` =\u003e `void Load(string html)`\\\n`ScrollCommand` =\u003e `Task ScrollAsync(string elementId)`\\\n`ScrollOnNextLoadCommand` =\u003e `void ScrollOnNextLoad(string elementId)`\\\n`SearchCommand` =\u003e `Task SearchAsync(string text)`\\\n`SearchOnNextLoadCommand` =\u003e `void SearchOnNextLoad(string text)`\\\n`SaveScrollPositionForNextLoadCommand` =\u003e `SaveScrollPositionForNextLoadAsync()`\\\n`PrintCommand` =\u003e `Task PrintAsync()`\\\n`ZoomCommand` =\u003e `void Zoom(double zoom)`\n\n### Loading HTML content\nTo load content into the viewer, bind an HTML string to it's `HtmlContent` property\n```XML\n\u003cdhv:HtmlViewer x:Name=\"htmlViewer\" HtmlContent=\"{Binding MyHtmlString}\" /\u003e\n```\nor use the `LoadCommand` and pass the HTML string as  the `CommandParameter`\n```XML\n\u003cButton\n    Command=\"{Binding ElementName=htmlViewer, Path=LoadCommand}\"\n    CommandParameter=\"{Binding MyHtmlString}\"\n    Content=\"Load HTML using a command\" /\u003e\n```\n\n### Link clicks\nWhenever a link is clicked in the loaded HTML file, the control fires the `LinkClickedCommand`. Bind you own command to that in order to handle link clicks, example:\n\nView.cs\n```XML\n\u003cdhv:HtmlViewer\n    x:Name=\"htmlViewer\"\n    LinkClickedCommand=\"{Binding MyLinkClickedCommand}\" /\u003e\n```\n\nViewModel.cs\n```Csharp\npublic ICommand MyLinkClickedCommand =\u003e new RelayCommand\u003cstring\u003e(HandleLinkClick);\n\nprivate void HandleLinkClick(string? link)\n{\n    Debug.WriteLine($\"Link clicked: {link}\");\n}\n```\n\n### Scroll to\nTo scroll to a specific element id, you have several options.\n\n`ScrollCommand`: tries to scroll to a specific element in the currently loaded HTML file\n```XML\n\u003cButton\n    Command=\"{Binding ElementName=htmlViewer, Path=ScrollCommand}\"\n    CommandParameter=\"elementId\"\n    Content=\"Scroll to elementId\" /\u003e\n```\n\n`ScrollOnNextLoadCommand`: will try to scroll to a specific element in the next loaded HTML file\n```XML\n\u003cButton\n    Command=\"{Binding ElementName=htmlViewer, Path=ScrollOnNextLoadCommand}\"\n    CommandParameter=\"elementId\"\n    Content=\"Scroll to elementId on next load\" /\u003e\n```\n\n### Save scroll position\nSaves the current scroll position and tries to restore it next time HTML content is loaded. If `ScrollOnNextLoad` is used as well, this will be ignored\n\n`SaveScrollPositionForNextLoadCommand`: will try to scroll to a specific element in the next loaded HTML file\n```XML\n\u003cButton\n    Command=\"{Binding ElementName=htmlViewer, Path=SaveScrollPositionForNextLoadCommand}\"\n    Content=\"Save scroll position for next load\" /\u003e\n```\n\n### Search\n\n`SearchCommand`: finds a search term on the current page\n```XML\n\u003cButton\n    Command=\"{Binding ElementName=htmlViewer, Path=SearchCommand}\"\n    CommandParameter=\"search text\"\n    Content=\"Search for text\" /\u003e\n```\n\n`SearchOnNextLoadCommand`: finds a search term in the next loaded HTML file\n```XML\n\u003cButton\n    Command=\"{Binding ElementName=htmlViewer, Path=SearchOnNextLoadCommand}\"\n    CommandParameter=\"search text\"\n    Content=\"Search for text on next load\" /\u003e\n```\n\n### Printing\n\nThe `PrintCommand` can be used to bring up the default print dialog window.\n```XML\n\u003cButton\n    Command=\"{Binding ElementName=htmlViewer, Path=PrintCommand}\"\n    Content=\"Show print dialog\" /\u003e\n```\n\n### Logging\nEnable logging for the control by configuring an `ILoggerFactory` provider like so:\n```csharp\nvar loggerFactory = LoggerFactory.Create(c =\u003e\n{\n    c.SetMinimumLevel(LogLevel.Debug);\n    c.AddDebug();\n});\n\nHtmlViewer.ConfigureLogger(() =\u003e loggerFactory);\n```\n\n### Virtual host name to folder path mapping\nSee [this page](https://docs.microsoft.com/en-us/dotnet/api/microsoft.web.webview2.core.corewebview2.setvirtualhostnametofoldermapping?view=webview2-dotnet-1.0.1108.44) to learn more.\n\nEnable virtual host name to folder path mapping like so:\n```csharp\nHtmlViewer.ConfigureVirtualHostNameToFolderMappingSettings(new VirtualHostNameToFolderMappingSettings\n{\n    Hostname = \"myfiles.local\",\n    FolderPath = @\"C:\\Resources\\MyFiles\",\n    AccessKind = Microsoft.Web.WebView2.Core.CoreWebView2HostResourceAccessKind.Allow\n});\n```\n\nYou can then access your assets like this in HTML:\n```html\n\u003chead\u003e\n    \u003clink href=\"https://myfiles.local/bootstrap.min.css\" rel=\"stylesheet\"\u003e\n\u003c/head\u003e\n\n\u003cbody\u003e\n    \u003cimg src=\"https://myfiles.local/my_image.jpg\" /\u003e\n\u003c/body\u003e\n```\n\n### Default browser background color\n\nConfigure the default background color of the control like so:\n\n```csharp\nusing System.Drawing;\n\nvar backgroundColor = Color.FromArgb(255, 24, 24, 24);\nHtmlViewer.ConfigureDefaultBackgroundColor(backgroundColor);\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichaldivis%2Fdark-html-viewer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmichaldivis%2Fdark-html-viewer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichaldivis%2Fdark-html-viewer/lists"}