OpenFin

WPF Embedded View

API Docs NuGet Example Project

Overview

Add the WindowsFormsIntegration namespace in your project references. Then, add the OpenFin XmlNamespace attribute to the root element of the markup file and place an EmbeddedView control in the screen.

<Window x:Class="WPF.Test.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:OpenFin="clr-namespace:Openfin.WPF;assembly=Openfin.WPF"
...
<OpenFin:EmbeddedView x:Name="OpenFinEmbeddedView"/>
...

Runtime Options

As the .NET API, we use the Runtime Options object to specify target runtime (alpha, beta, 32/64 bits…etc), enabling remote debugging, specify local assets…etc, for a complete list of options see our documentation.

Please include your licenseKey in RuntimeOptions.LicenseKey when launching apps from the .NET Adapter. If you’re interested in an Enterprise license, please contact us for one here.

var runtimeOptions = new Openfin.Desktop.RuntimeOptions
{
    Version = "alpha",
    EnableRemoteDevTools = true,
    RemoteDevToolsPort = 9090
};

Application options

The Application Options object allows you to configure the OpenFin Application being embedded, options include: name, URL, icon and window options…etc, for a complete list of options see our documentation.

var appOptions = new Openfin.Desktop.ApplicationOptions("of-chart", 
    "of-chart-uuid", "http://cdn.openfin.co/embed-web/chart.html");

Initialize

The EmbeddedView needs to be initialized with both the RuntimeOptions object and the ApplicationOptions object:

OpenFinEmbeddedView.Initialize(runtimeOptions, appOptions);

Ready

To programatically react to when the EmbeddedView has loaded its content and is ready to be displayed, you can subscribe to the Ready event:

OpenFinEmbeddedView.Ready += (sender, e) =>
{
    // EmbeddedView events are automatically raised on the UI thread
    Title = "OpenFinEmbeddedView is ready";
};

Embedding child windows

The OpenFinEmbeddedView allows you to embed web applications, these have their own render process and sandbox, but it also allows you to embed child windows that can share the same render process and sandbox, adding the risk of one window crashing the other but using less resources.

OpenFinEmbeddedView.Ready += (sender, e) =>
{
    //We need to create our WindowOptions Object
    var windowOptions = new Openfin.Desktop.WindowOptions("jsdocs", "http://cdn.openfin.co/jsdocs/alpha/");

    //Assuming we have added a second EmbeddedView called OpenFinEmbeddedViewChild
    //we initialize it.
    OpenFinEmbeddedViewChild.Initialize(runtimeOptions,
        OpenFinEmbeddedView.OpenfinApplication, windowOptions)
}

Runtime object

Every EmbeddedView control that shares a RuntimeOptions object shares a connection to the OpenFin Runtime. You can obtain this singleton object via the Runtime.GetRuntimeInstance function. It allows you to publish and subscribe to Inter Application Bus messages, react to disconnect events, and initiate connect calls (this is optional and unnecessary in the case where one or more EmbeddedView control has been initialized).

var runtime = Runtime.GetRuntimeInstance(runtimeOptions);
runtime.Connect(() => 
{
    //Any Interactions with the UI must be done in the right thread.
    Openfin.WPF.Utils.InvokeOnUiThreadIfRequired(this, () => 
        Title = "OpenFin Runtime is connected");

    //subscribe to hello-from-bus messages from any application
    InterApplicationBus.Subscription(runtime, "hello-from-bus").MessageReceived += (s, e) =>
    {
        var dataAsJObject = e.Message;
        Openfin.WPF.Utils.InvokeOnUiThreadIfRequired(this, () =>
            Title = dataAsJObject.GetValue("message"));
    });
});

Have questions? Get in touch with us at support@openfin.co.

WPF Embedded View


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.