WebView2 on X# VOForm: empty when using CustomControl
Posted: Mon Mar 14, 2022 9:49 pm
Earlier I asked about applying the WebView2 in X#. On https://www.xsharp.eu/forum/public-prod ... t=20#21737, where Frank Müßner posted an example how to add a Winforms PictureBox on an X# VO form. With a slight modification in SetParent the fully prepared PictureBox could be assigned to a VO CustomerControl
So I thought I do about the same to add a WebView2 control to a VO form. I installed the 3 necessary DLL's via a NuGet package, used the same CustumControl odcPict on the VO form and used this code in the PostInit. But the control remains empty, both when I use an existing html file or a valid URI (now outcommented).
What do I miss? It works with a few lines of code on an X# Winforms program or a WPF program.
EDIT: it does work when I directly assign the content to the window (like in Frank's oroginal sample). But why doesn't it work in a X# CustomControl?
See listing 2
Dick
Listing2 : it works when I do not use the customcontrol: and use Self:Handle again in SetParent:
Code: Select all
SetParent(Self:pictureBox1:Handle, Self:oDCPict:Handle())
So I thought I do about the same to add a WebView2 control to a VO form. I installed the 3 necessary DLL's via a NuGet package, used the same CustumControl odcPict on the VO form and used this code in the PostInit. But the control remains empty, both when I use an existing html file or a valid URI (now outcommented).
What do I miss? It works with a few lines of code on an X# Winforms program or a WPF program.
EDIT: it does work when I directly assign the content to the window (like in Frank's oroginal sample). But why doesn't it work in a X# CustomControl?
See listing 2
Dick
Code: Select all
Using Microsoft.Web.WebView2.CorePartial Class Window1 Inherit DATAWINDOW
Protect webView2 As Microsoft.Web.WebView2.WinForms.WebView2
Protect oDCPICT As CUSTOMCONTROL
Code: Select all
Self:webView2 := Microsoft.Web.WebView2.WinForms.WebView2{}
Self:webView2:Visible:=True
cHTMLPath:="c:tempSomeFile.html"
Self:webView2:Source := System.Uri{cHTMLPath, System.UriKind.Absolute}
//Self:webView2:Source := System.Uri{"https://www.xsharp.eu", System.UriKind.Absolute}
Self:webView2:Update()
SetParent(Self:webViewEmail:Handle, Self:oDCPict:Handle())
Code: Select all
Self:webViewEmail := Microsoft.Web.WebView2.WinForms.WebView2{}
Self:webViewEmail:Visible:=True
Self:webViewEmail:Location := System.Drawing.Point{1, 1}
Self:webViewEmail:Size := System.Drawing.Size{800, 800}
Self:webViewEmail:Source := System.Uri{"https://www.xsharp.eu", System.UriKind.Absolute}
Self:webViewEmail:Update()
SetParent(Self:webViewEmail:Handle, Self:Handle())