Need simple MVVM example hooking up component as it loads #3609
Replies: 1 comment 3 replies
-
The http://cefsharp.github.io/api/90.6.x/html/F_CefSharp_Wpf_ChromiumWebBrowser_IsLoadingProperty.htm dependency property is equivalent to LoadingStateChange event.
LoadingStateChange would be too late to enable legacy JavaScript Binding. It's unlikely you'd be able to set LegacyBindingEnabled in a ViewModel, it needs to be set before the underlying CEF browser is created and cannot be changed after. Subclassing ChromiumWebBrowser and setting the value in the constructor is likely the only option currently. Possibly an event could be added, there are a few other use cases where this might be useful.
The http://cefsharp.github.io/api/90.6.x/html/E_CefSharp_IJavascriptObjectRepository_ResolveObject.htm event can be used. Once you have set LegacyBindingEnabled |
Beta Was this translation helpful? Give feedback.
-
I need to avoid using code behind and I've been trying to figure out how to hook up to an event like LoadingStateChanged. I keep getting thread errors when the component tries to load. This way I can grab onto the control instance itself. Is there a simple pure MVVM example (with zero code-behind) that shows how to hook up some of the commands (especially loading) to a viewmodel?
Ultimately, I'm trying to initialize the cefSharp browser instance with something like this:
ChromiumBrowser cefControl = sender as ChromiumBrowser;
cefControl.JavascriptObjectRepository.Settings.LegacyBindingEnabled = true;
cefControl.JavascriptObjectRepository.Register("cefTestClass", testClass, isAsync: false, options: BindingOptions.DefaultBinder);
I've tried to use the Loaded event, but even though it shows that the Command is being setup (in the getter), the event itself never fires off (and neither did Initialized when I tested that one, too), but the Unloaded event does fire off fine:
My next challenge will be how to do that registration of the JavascriptObjectRepository of the test class instance. An MVVM example of that would also be superb!
Thanks.
Beta Was this translation helpful? Give feedback.
All reactions