JSB - Wpf.Example update to use ResolveObject method for testing fix for #2273

This commit is contained in:
amaitland
2018-02-13 12:55:01 +10:00
parent 43b427bd00
commit be50b75648
@@ -12,6 +12,7 @@ using CefSharp.Wpf.Example.Handlers;
using CefSharp.Wpf.Example.ViewModels;
using System.IO;
using CefSharp.Example.ModelBinding;
using System.Diagnostics;
namespace CefSharp.Wpf.Example.Views
{
@@ -32,9 +33,9 @@ namespace CefSharp.Wpf.Example.Views
browser.RegisterJsObject("bound", new BoundObject(), options: BindingOptions.DefaultBinder);
}
else
{
//Register the new way
browser.JavascriptObjectRepository.Register("bound", new BoundObject(), isAsync:false, options: BindingOptions.DefaultBinder);
{
//Objects can still be pre registered, they can also be registered when required, see ResolveObject below
//browser.JavascriptObjectRepository.Register("bound", new BoundObject(), isAsync:false, options: BindingOptions.DefaultBinder);
}
var bindingOptions = new BindingOptions()
@@ -50,10 +51,14 @@ namespace CefSharp.Wpf.Example.Views
}
else
{
//Register the new way
browser.JavascriptObjectRepository.Register("boundAsync", new AsyncBoundObject(), isAsync: true, options: bindingOptions);
//Objects can still be pre registered, they can also be registered when required, see ResolveObject below
//browser.JavascriptObjectRepository.Register("boundAsync", new AsyncBoundObject(), isAsync: true, options: bindingOptions);
}
//To use the ResolveObject below and bind an object with isAsync:false we must set CefSharpSettings.WcfEnabled = true before
//the browser is initialized.
CefSharpSettings.WcfEnabled = true;
//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) =>
@@ -63,11 +68,21 @@ namespace CefSharp.Wpf.Example.Views
{
repo.Register("boundAsync2", new AsyncBoundObject(), isAsync: true, options: bindingOptions);
}
else if(e.ObjectName == "bound")
{
browser.JavascriptObjectRepository.Register("bound", new BoundObject(), isAsync: false, options: BindingOptions.DefaultBinder);
}
else if( e.ObjectName == "boundAsync")
{
browser.JavascriptObjectRepository.Register("boundAsync", new AsyncBoundObject(), isAsync: true, options: bindingOptions);
}
};
browser.JavascriptObjectRepository.ObjectBoundInJavascript += (sender, e) =>
{
var name = e.ObjectName;
Debug.WriteLine($"Object {e.ObjectName} was bound successfully.");
};
browser.DisplayHandler = new DisplayHandler();