Edge control in an X# application

This forum is meant for examples of X# code.

User avatar
wriedmann
Posts: 3755
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Edge control in an X# application

Post by wriedmann »

Hi all,

it is a common requirement these days to have a webbrowser control in a Windows application. For this we can use the Internet Explorer control. But since the IE is very limited, now there is the possibility to have Edge as control, but it needs at least Windows 10 version 1803 or 1809.
Please see this page: https://docs.microsoft.com/en-us/window ... ms/webview

And today I was able to make it work in a WPF application written in pure X#:
EdgeWPFApp.png
EdgeWPFApp.png (54.43 KiB) Viewed 826 times
The code is really simple:

Code: Select all

oWebView := WebView{}
oWebView:Name := "WebBrowser"
I have added a XIDE export file here (it contains also the needed control, extracted from the relative Nuget package):
WebViewWPFApp.zip
(137.82 KiB) Downloaded 140 times
The Nuget packages are here (please don't use the prerelease version, it does not work):
https://www.nuget.org/packages/Microsof ... 0-preview3
https://www.nuget.org/packages/Microsof ... 0-preview3

Unfortunately until now I was not able to make work the WinForms version - it would be cool thing to add such a control as OLE control in VO applications.

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
George
Posts: 106
Joined: Thu Nov 05, 2015 9:17 am

Edge control in an X# application

Post by George »

Wolfgang

very interesting!

My apps use the .Net WebViewer and I think I have to change it.
I will give it a try in a WinForm application.

thanks
George
User avatar
Fabrice
Posts: 459
Joined: Thu Oct 08, 2015 7:47 am
Location: France

Edge control in an X# application

Post by Fabrice »

Hi Wolfgang,

may I suggest to take a look at CefSharp (http://cefsharp.github.io/ ) ?
Works with Framework 4.5.2; Exist in WinForms or WPF flavour, and available as a NuGet package

HTH,
Fabrice
XSharp Development Team
fabrice(at)xsharp.eu
User avatar
wriedmann
Posts: 3755
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Edge control in an X# application

Post by wriedmann »

Hi Fabrice,

thank you very much! I will try it out. Until now I had only found paid packages, with prices varying from 800 to 2000 Euro/year.

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
Fabrice
Posts: 459
Joined: Thu Oct 08, 2015 7:47 am
Location: France

Edge control in an X# application

Post by Fabrice »

Wolfgang,
I've used it in C# project with Students : Easy to use, build on Chromium...even Microsoft has embrace WebKit, so it might be a good solution ! :)
And for an X# usage, the NuGet package is a luxury !

Regards
Fabrice
XSharp Development Team
fabrice(at)xsharp.eu
ic2
Posts: 1858
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

Edge control in an X# application

Post by ic2 »

Hello Wolfgang,

This is really interesting. We use a OCX which is unfortunately not maintained by the maker to edit & display e-mails. We would love to replace it by something else for 2 main reasons:
1 We would like to edit text and have a direct spell check as I have in Firefox where I can also select the language.
2 When we control click a hyperlink it always opens in IE regardless the default browser.

However none of the above works in the Edge based control. It is not even possible to open a hyperlink in your own browser (Ctrl or Shift Click doesn't do anything) and there is no spell check either.

I checked the same in Edge (which i never use) and see that Ctrl or Shift click doesn't use my default browser either (it opens a new Edge or Edge tab) and spell check is also apparently been to difficult for Microsoft to implement :).

There is a right mouse menu with Paste/Select all/Print/Read aloud in it, which is missing in the control exe as well.

Do you think this behavior can be changed using the control?

Dick
User avatar
wriedmann
Posts: 3755
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Edge control in an X# application

Post by wriedmann »

Hi Dick,

I don't know what Edge gives for possibilities. I have also tried CefSharp which Fabrice had suggested, but I was not able to make it work - it seems to have to do with the fact that it needs different DLL sets for x86 and x64.
But Edge itself is changed, so in a foreseable future it will loose its own engine and use Chromium (the engine used by Chrome).
Spell check is a difficult thing, specially for non-english languages because it needs dictionaries and more logic.
In the Edge based control you have a callback when a link is clicked, and therefore you can decide what to do with it. (this also the case with the IE based control).
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
Fabrice
Posts: 459
Joined: Thu Oct 08, 2015 7:47 am
Location: France

Edge control in an X# application

Post by Fabrice »

Hi Wolfgang,

sorry to hear you had trouble to make CefSHarp working...
So, I've tried myself to make it with X# (as I said before, I had only done it with C# in a student project).

Ok, it was a bit tricky, but it's ok now...and by the way, I've found different problem with my VS Integration ;)
CefSample.jpg
CefSample.jpg (140.76 KiB) Viewed 827 times
I can send you my working project, and maybe should do an "How-to" article about it...or better, create a Video for the XSharp Academy on YouTube...24h/Day is definitively too short !
XSharp Development Team
fabrice(at)xsharp.eu
User avatar
wriedmann
Posts: 3755
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Edge control in an X# application

Post by wriedmann »

Hi Fabrice,

I've tried first using XIDE (some things are simpler there <g>), but strangely in the CefSharp version I have there is no more an static Initialize() method in the Cef class - I've looked also with Reflector to be sure, but it is not there.
Then I have tried using Visual Studio and NuGet, but I was not able to set the platform to x64 or to x32, since AnyCPU does not work.
Unfortunately, in my experience, open source projects sometimes have the bad habit to change interfaces or something else and don't try to make things easier.
I have suspended (but not stopped!) my tries to make it work - it is too important to have a working browser available in my applications.
And CefSharp seems to have some very unique features, like access from Javascript to the internal objects of the C#/X# side, and the possibility to call JavaScript methods from the C#/X# side.
The most important for me would be to have a working HTML editor, but they seem to be available only as JavaScript applications, not as Windows components. So the way to go seems to be an embedded browser with an embedded JavaScript HTML editor.
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
Fabrice
Posts: 459
Joined: Thu Oct 08, 2015 7:47 am
Location: France

Edge control in an X# application

Post by Fabrice »

Wolfgang,

in fact there are several showstopper :
You will need to edit the XSharp project file and put some "magic" there, then add an app.config with some settings
...and the Initialize method is here, but I (currently) don't know why it doesn't appear with Intellisense (one of the problem)

I will check the HTML editor part, and come back with some "Step-by-step" instructions...for Visual Studio, sorry ;)
XSharp Development Team
fabrice(at)xsharp.eu
Post Reply