/** * Function: ShowMDView * * Shows the md view. * * Author: wellinthatcase * * Date: 12/25/2020 */ private void ShowMDView() { HideEditor(); ToggleMD.IsChecked = true; MarkdownW.Visibility = Visibility.Visible; MarkdownW.Focus(); }
/** * Function: StartMDView * * Starts md view. This pre-loads boilerplate HTML & CSS into the WebView2. * * Author: wellinthatcase * * Date: 12/25/2020 */ private async void StartMDView() { if (!UnloadedWv2Check()) { return; } await MarkdownW.EnsureCoreWebView2Async(); string cssString = ":not(h1,h2,h3,h4,h5,h6) { font-size: 11px; } :not(br) { overflow: hidden visible; background-color: rgb(15, 2, 2); color: rgb(242, 238, 229); font-family: Segoe UI,Frutiger,Frutiger Linotype,Dejavu Sans,Helvetica Neue,Arial,sans-serif; margin-top: 1.5px; margin-bottom: 3px; }"; string htContent = string.Format("<!DOCTYPE html><html><head><link rel='stylesheet' type='text/css'" + "href='data:text/css;charset=UTF-8,{0}'></head><body></body></html>", Uri.EscapeUriString(cssString)); MarkdownW.NavigateToString(htContent); }
/** * Function: UnloadWebView2 * * Control: Logo * * Event: Click * * Unload WebView2. Slices memory usage in half. * * Author: wellinthatcase * * Date: 12/25/2020 * * Parameters: * sender - Source of the event. * e - Routed event information. */ private void UnloadWebView2(object sender, RoutedEventArgs e) { MarkdownW.Dispose(); WebView2Active = false; }
/** * Function: HideEditor * * Hides the editor. * * Author: wellinthatcase * * Date: 12/25/2020. */ private void HideEditor() { MarkdownW.BringIntoView(); TextEntry.Visibility = Visibility.Hidden; }
/** * Function: ExecScript * * Executes a JS script inside the WebView2 embedded browser. * * Author: wellinthatcase * * Date: 12/28/2020 * * Parameters: * code - The code. * * Returns: True if it succeeds, false if it fails. */ private bool ExecScript(string code) => MarkdownW.ExecuteScriptAsync(code).IsCompleted;