Questions about adding an event handlers

This forum is meant for questions and discussions about the X# language and tools
Post Reply
ic2
Posts: 1856
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

Questions about adding an event handlers

Post by ic2 »

Although I am working from some C# samples the question I've got here would apply equally to X#.

I am trying to implement the WebView2. When I click an URL in this control, it always opens a new Webview2 Runtime component (without menu's) showing the URL. I want a URL click executed in the the existing Webview2 control and e.g. a Ctrl or Shift click open in my default browser (Firefox).

Several webpages refer to NewWindowRequested. Apart from that none of the solution work (EDIT: it works but always, seems an issue) this puzzles me:

This event handler can be added to my Webview2 component:

webView.NavigationStarting += SomeMethod;
(After typing the dot, I can select NavigationStarting).

But this can not (and does not complete either after typing the dot):

webView.NewWindowRequested +=SomethingElse.

I need to use:
webView.CoreWebView2.NewWindowRequested += CoreWebView2_NewWindowRequested;

CoreWebView2 is "an underlying API" I can see in a tooltip. But in the api documentation (https://docs.microsoft.com/en-us/dotnet ... 1.0.774.44) both methods are described on the same level.

So how can I know that these methods need to be called differently?

I now found it after lot's of searching for samples on the internet.

Dick
TerryB1
Posts: 306
Joined: Wed Jan 03, 2018 11:58 am

Questions about adding an event handlers

Post by TerryB1 »

Hi Dick
WindowsForms WebView Control is pretty much state-of-the-art stuff in the C# world.
It allows you to present data to users in fixed format but alternative ways. The coding behind these “ways” can be extremely complex and therefore best left to an expert.
Using the WebView control allows just that. You do not need to think “how can I code things up to display this data ?”, but rather “what are the alternative (professional, commonly understood) ways of displaying this data?”
You can then select the way you like best. Presentation is thus in the hands of the professional, allowing you to tweak things such as color, annotations and so on.

The best way to understand all this is to get a book say, covering Charts and Graphics. All the details, as deep as you want to go will be covered in such a book.
“Practical C# Charts and Graphics Second Edition” Jack Xu. https://drxudotnet.com
It will introduce you to Gincker Graphics which need little code to use.


Hope that helps.
Terry
ic2
Posts: 1856
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

Questions about adding an event handlers

Post by ic2 »

Hello Terry,

Thanks for replying but I think you kind of missed what I wanted to know. Basically I want to understand how I should be able to see that I need to add .CoreWebView2 for one event and not for the other , while both are documented by Microsoft the same way.

I am not looking for deep insight how charts & graphics work :lol:
BTW: the WebView2 control is not exclusively Winforms. My testproject is WPF but it looks like we can even use it in Win32, so if I find out how also in VO. In that case I can use it sooner than when I have an X# version of that part of the program.
Dick
TerryB1
Posts: 306
Joined: Wed Jan 03, 2018 11:58 am

Questions about adding an event handlers

Post by TerryB1 »

Hi Dick
Sorry, yes, I put pen to paper too quickly and missed your point. Nevertheless, I do think that taking a look thorough C# and WebView2 at Gincker would be instructive. A couple of hours at most will show what can be offered via WebView2.
As far as doing this via VO, I do know of at least one VO project where its functionality (using WPF / XAML) has been used to control a complex model in much the same way.
Bearing in mind the current state of play in the Microsoft dotNet world, particularly WebView2 – a control with which MS is still tinkering about with – it occurs to me that an alternative approach to what you want to achieve may be worth some thought.
The whole dotnet picture is evolving, not so much because of what I will call “feature enhancement or modification” (but of course that plays a part), but rather the place where such modifications are implemented.

Of course, this impacts on code across the board.

Net5 is just around the corner. It also impacts on C# compilation, code and so on.

I suggest, therefore, that in order to meet your objective as I understand it, it would be worth considering implementation through C# (Net5?) in a separate assembly, then when XSharp offers the required capabilities and WebView2 has settled down (by which time we’ll be on WebView22!) you’ll be able to massage your program structure and assemblies putting it all into XSharp.

Incidentally when I last tried to use WebView2 via the designer it didn't work, much easier to do it in code, and instantiate through the handler of a button click.

Hope that makes sense and that I’ve interpreted your objective correctly.
Terry
ic2
Posts: 1856
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

Questions about adding an event handlers

Post by ic2 »

Hello Terry,

Well, it's definitely not a big deal, the reply I was looking for and you may well be right that digging deeper into how everything works could learn me why I should use one solution for one method and another for the the other method. What I basically expect is that I can find what to use from documentation without digging into the background or (the usual solution) open a dozen or more search results.
Terry wrote: The whole dotnet picture is evolving, not so much because of what I will call “feature enhancement or modification” (but of course that plays a part), but rather the place where such modifications are implemented.


Incidentally when I last tried to use WebView2 via the designer it didn't work, much easier to do it in code, and instantiate through the handler of a button click.

I can give you a literal reply on the 1st remark ;) : the place where the modifications will be implemented is in Suzhou, China. They are hiring a new team according to https://github.com/MicrosoftEdge/WebVie ... issues/980. Made in China....This (or the current team) is not quick in reacting, quite some questions, feature requests or bugs have not been assigned to anyone days after they are posted.

And for the second: I have built a working WPF based window to show e-our mails, currently still as an extra/alternative to the regular VO window. The code is placed in our .Net DLL we can use from within our VO programs; the solution is a mix of C# and X# code. This all seems to work fine.

Dick
Post Reply