Skip to content

Commit

Permalink
JSB - Wpf.Example update to use ResolveObject method for testing fix …
Browse files Browse the repository at this point in the history
…for #2273
  • Loading branch information
amaitland committed Feb 13, 2018
1 parent 43b427b commit be50b75
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions CefSharp.Wpf.Example/Views/BrowserTabView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using CefSharp.Wpf.Example.ViewModels;
using System.IO;
using CefSharp.Example.ModelBinding;
using System.Diagnostics;

namespace CefSharp.Wpf.Example.Views
{
Expand All @@ -32,9 +33,9 @@ public BrowserTabView()
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()
Expand All @@ -50,10 +51,14 @@ public BrowserTabView()
}
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) =>
Expand All @@ -63,11 +68,21 @@ public BrowserTabView()
{
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();
Expand Down

0 comments on commit be50b75

Please sign in to comment.