CefSharp.MinimalExample
CefSharp.MinimalExample copied to clipboard
Made an MVVM friendly example.
I altered the example to comply better with MVVM. Added a Behavior for loading an HTML string as the web page, BUT this isn't working yet, so I am hoping you can explain me better what's going on so I can fix this and this code can be merged with the main project as well.
It's probably a timing issue, have a look at the source for LoadHtml, it does two things. In WPF, your best to set the Address property as it is an actual DependencyProperty. If all you care about is loading some Html (and no what the address bar url looks) then just generate a Data Uri.
As a general comment, don't you think this deviates aware from the MinimalExample implication? (I know your just trying to get your behavior working at the moment).
Also it looks like you've used features that aren't available in .Net 4.5.2, which should probably stay as the default as that's the minimum requirement to use the current version.
If all you care about is loading some Html
What else should LoadHtml do? I don't get it's purpose for something else. Should we add a LoadHtml that only takes one parameter, the HTML as a string and render it?
In my application, using a default WPF WebBrowser, I bind a ICollectionView of strings with HTMLs to a ListBox, and the CurrentItem is bound in XAML with the WebBrowser Address, so just as the user clicks a new ListBoxItem the item is rendered automagically into the WebBrowser. I was expecting to do something similar here and through a behavior was my first idea for binding the string directly.
As a general comment, don't you think this deviates aware from the MinimalExample implication?
If we should provide a minimum WPF MVVM Example, no, but if it's meant to be a quick WPF example, than yes. But the behaviors I would remove them and transfer to the other project, I just thought a minimal example was good to test this kind of stuff. Honestly, whatever you decide on this I back you 100%, it's a bit gray area.
Also it looks like you've used features that aren't available in .Net 4.5.2
Like what?
Like what?
Null Conditional Operator e.g. _TargetExecuteMethod?.Invoke((T)parameter); won't work in .Net 4.5.2
Isn't the Null Conditional Operator a C# 6.0 feature and not a .NET feature? So it's up to the compiler (VS version) and not .NET (since the framework will just be interpreting the CLI compiled by VS)?
Isn't the Null Conditional Operator a C# 6.0 feature and not a .NET feature? So it's up to the compiler (VS version) and not .NET (since the framework will just be interpreting the CLI compiled by VS)?
It is compiler magic. If you don't happen to have .Net 4.6 installed you won't be able to compile. Also if you open in VS2013 and only target .Net 4.5.2 (Like I did on this machine) you'll have compiler errors.
Ok, I will remove the ? then.
This last update works! Should I leave it like this or should we improve the library instead an remove the URL?
I am reading the LoadHtml code and it appears to be registering a new Handler to a Dictionary every time a new HTML is loaded. Are the handlers removed at any point? Can't this lead to a memory leak?
Are the handlers removed at any point?
Automatically no. They are overwritten if you register the same Url though.
Can't this lead to a memory leak?
It can of course. It's a very simplistic implementation, just there for convenience. You can of course take full control and even implement your own IResourceHandlerFactory. The default implementation has a method to remove a Url. You'd have to call it manually,
The alternative is a Data Uri, like https://github.com/cefsharp/CefSharp/blob/a94bbdd593fb72a2edc92fcfe4987c505802e768/CefSharp.WinForms.Example/BrowserForm.cs#L475
(Base64 encoding is just one option) see https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs