WPF Example - Add LegacyBinding options and some better comments

This commit is contained in:
amaitland
2018-01-22 12:33:48 +10:00
parent fd64b079a2
commit e47157f195
@@ -25,13 +25,37 @@ namespace CefSharp.Wpf.Example.Views
InitializeComponent();
browser.RequestHandler = new RequestHandler();
browser.JavascriptObjectRepository.Register("bound", new BoundObject(), isAsync:false, options: BindingOptions.DefaultBinder);
//See https://github.com/cefsharp/CefSharp/issues/2246 for details on the two different binding options
if(CefSharpSettings.LegacyJavascriptBindingEnabled)
{
browser.RegisterJsObject("bound", new BoundObject(), options: BindingOptions.DefaultBinder);
}
else
{
//Register the new way
browser.JavascriptObjectRepository.Register("bound", new BoundObject(), isAsync:false, options: BindingOptions.DefaultBinder);
}
var bindingOptions = new BindingOptions()
{
Binder = BindingOptions.DefaultBinder.Binder,
MethodInterceptor = new MethodInterceptorLogger() // intercept .net methods calls from js and log it
};
browser.JavascriptObjectRepository.Register("boundAsync", new AsyncBoundObject(), isAsync: true, options: bindingOptions);
//See https://github.com/cefsharp/CefSharp/issues/2246 for details on the two different binding options
if(CefSharpSettings.LegacyJavascriptBindingEnabled)
{
browser.RegisterAsyncJsObject("boundAsync", new AsyncBoundObject(), options: bindingOptions);
}
else
{
//Register the new way
browser.JavascriptObjectRepository.Register("boundAsync", new AsyncBoundObject(), isAsync: true, options: bindingOptions);
}
//If you call CefSharp.BindObjectAsync in javascript and pass in the name of an object which is not yet
//bound, then ResolveObject will be called, you can then register it
browser.JavascriptObjectRepository.ResolveObject += (sender, e) =>
{
var repo = e.ObjectRepository;