mirror of
https://github.com/cefsharp/CefSharp.git
synced 2026-12-06 12:09:40 +00:00
WPF Example - Add LegacyBinding options and some better comments
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user