You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using a WPF WebView2CompositionControl to display an instance of Monaco Editor, but the content is blurry. It looks like the content is rendered for a wrong DPI value.
At first I used the WebView2 control but this control has the issue that it is always shown on top of all other WPF controls. So I switched to the WebView2CompositionControl, the overlaying issue is fixed now, but the content is blurred. This was not the case when I used the WebView2 control.
Importance
Moderate. My app's user experience is affected, but still usable.
Runtime Channel
Stable release (WebView2 Runtime)
Runtime Version
No response
SDK Version
No response
Framework
WPF
Operating System
Windows 11
OS Version
No response
Repro steps
Steps to reproduce
Use this HTML for Monaco editor:
<!DOCTYPE html><htmllang="en"><head><title>Editor</title><metahttp-equiv="Content-Type" content="text/html;charset=utf-8"/><linkrel="stylesheet"
data-name="vs/editor/editor.main"
href="./min/vs/editor/editor.main.css"/><style>html,body {
height:100%;
margin:0;
}
#container {
height:100%;
}
</style></head><body><divid="container"></div><scriptsrc="./min/vs/loader.js"></script><script>require.config({paths: {'vs': './min/vs'}});</script><scriptsrc="./min/vs/editor/editor.main.js"></script><script>// Hold a reference to the Monaco editor instanceletmonacoEditor;// Function to initialize the editorfunctioninitializeEditor(content,theme='vs-light'){require(['vs/editor/editor.main'],function(){if(monacoEditor){return;}monacoEditor=monaco.editor.create(document.getElementById('container'),{value: content.toString(),automaticLayout: true,theme: theme,});});// Add a resize listener to resize Monaco Editor dynamicallywindow.addEventListener('resize',()=>{if(monacoEditor){monacoEditor.layout();}});}</script></body></html>
usingCommunityToolkit.Mvvm.Input;usingMicrosoft.Web.WebView2.Core;usingMicrosoft.Web.WebView2.Wpf;usingSystem;usingSystem.IO;usingSystem.Threading.Tasks;usingSystem.Windows;usingSystem.Windows.Controls;usingSystem.Windows.Input;usingSystem.Windows.Media;usingJsonSerializer=System.Text.Json.JsonSerializer;namespaceExample.TextEditor;publicpartialclassTextEditor:UserControl{publicTextEditor(){InitializeComponent();TextEditorView.Source=newUri(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,@"Monaco\editor.html"));}privateasyncTaskInitializeEditorAsync(){if(_isEditorInitialized){return;}varjavaScriptString=ConvertToJavaScriptString(Text);varscript=$"initializeEditor({javaScriptString})";awaitExecuteJavaScriptAsync(script,TextEditorView);_isEditorInitialized=true;}privateasyncTask<string>ExecuteJavaScriptAsync(stringscript,WebView2CompositionControlwebview){awaitwebview.EnsureCoreWebView2Async();// Call the script in the WebView2 (this executes in the loaded HTML/JS context)varresult=awaitwebview.CoreWebView2.ExecuteScriptAsync(script);if(!string.IsNullOrEmpty(result)){result=ConvertToCSharpString(result);}returnresult;}privatestringConvertToJavaScriptString(stringtext){// JSON is compatible to JavaScriptreturnJsonSerializer.Serialize(text);}privatestringConvertToCSharpString(stringjavaScriptString){// JSON is compatible to JavaScriptreturnJsonSerializer.Deserialize<string>(javaScriptString);}privateasyncvoidTextEditorView_OnNavigationCompleted(objectsender,CoreWebView2NavigationCompletedEventArgse){try{awaitInitializeEditorAsync();}catch(Exceptionexception){Console.WriteLine(exception);}}}
Expected Behavior
WebView2CompositionControl displays the HTML content exactly as the WebView2 control correctly rendered.
Actual Behavior
WebView2CompositionControl displays the HTML content blurred.
Repros in Edge Browser
No, issue does not reproduce in the corresponding Edge version
Regression
No, this never worked
Last working version (if regression)
No response
The text was updated successfully, but these errors were encountered:
I just found out that setting UseLayoutRounding="True" on the parent window fixes the problem. However, the other controls now look very sharp-edged. Unfortunately, setting it on the WebView2CompositionControl itself doesn't have any effect.
What happened?
I'm using a WPF
WebView2CompositionControl
to display an instance of Monaco Editor, but the content is blurry. It looks like the content is rendered for a wrong DPI value.At first I used the
WebView2
control but this control has the issue that it is always shown on top of all other WPF controls. So I switched to theWebView2CompositionControl
, the overlaying issue is fixed now, but the content is blurred. This was not the case when I used theWebView2
control.Importance
Moderate. My app's user experience is affected, but still usable.
Runtime Channel
Stable release (WebView2 Runtime)
Runtime Version
No response
SDK Version
No response
Framework
WPF
Operating System
Windows 11
OS Version
No response
Repro steps
Steps to reproduce
Use this HTML for Monaco editor:
Use this WPF XAML:
Code behind:
Expected Behavior
WebView2CompositionControl
displays the HTML content exactly as theWebView2
control correctly rendered.Actual Behavior
WebView2CompositionControl
displays the HTML content blurred.Repros in Edge Browser
No, issue does not reproduce in the corresponding Edge version
Regression
No, this never worked
Last working version (if regression)
No response
The text was updated successfully, but these errors were encountered: