Show / Hide Table of Contents

Class Interop

Provides static methods for executing JavaScript code from within C#.

Inheritance
System.Object
Interop
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: OpenSilver
Assembly: OpenSilver.dll
Syntax
public static class Interop

Properties

| Improve this Doc View Source

DumpAllJavascriptObjectsEveryMs

Declaration
public static int DumpAllJavascriptObjectsEveryMs { get; set; }
Property Value
Type Description
System.Int32
| Improve this Doc View Source

DumpAllJavascriptObjectsFilter

Declaration
public static Func<string, string, bool> DumpAllJavascriptObjectsFilter { get; set; }
Property Value
Type Description
System.Func<System.String, System.String, System.Boolean>
| Improve this Doc View Source

DumpAllJavascriptObjectsLogger

Declaration
public static Action<string> DumpAllJavascriptObjectsLogger { get; set; }
Property Value
Type Description
System.Action<System.String>
| Improve this Doc View Source

DumpAllJavascriptObjectsStackTraceCount

Declaration
public static int DumpAllJavascriptObjectsStackTraceCount { get; set; }
Property Value
Type Description
System.Int32
| Improve this Doc View Source

DumpAllJavascriptObjectsVerbose

Declaration
public static bool DumpAllJavascriptObjectsVerbose { get; set; }
Property Value
Type Description
System.Boolean
| Improve this Doc View Source

IsRunningInTheSimulator

Returns True is the app is running in the simulator, and False otherwise.

Declaration
public static bool IsRunningInTheSimulator { get; }
Property Value
Type Description
System.Boolean
| Improve this Doc View Source

IsRunningInTheXamlDesigner

Returns True if the app is running inside the Xaml Designer, and False otherwise.

Declaration
public static bool IsRunningInTheXamlDesigner { get; }
Property Value
Type Description
System.Boolean

Methods

| Improve this Doc View Source

CreateJavascriptCallback(Delegate)

Register a .NET method to allow it to be invoked from JavaScript code.

Declaration
public static IDisposable CreateJavascriptCallback(Delegate d)
Parameters
Type Name Description
System.Delegate d
Returns
Type Description
System.IDisposable

An System.IDisposable object that must be disposed after it has been used. If the object is not disposed, it will be leaked.

| Improve this Doc View Source

ExecuteJavaScript(String)

Allows calling JavaScript code from within C#.

Declaration
public static IDisposable ExecuteJavaScript(string javascript)
Parameters
Type Name Description
System.String javascript

The JavaScript code to execute.

Returns
Type Description
System.IDisposable

The result, if any, of the JavaScript call.

| Improve this Doc View Source

ExecuteJavaScript(String, Object[])

Allows calling JavaScript code from within C#.

Declaration
public static IDisposable ExecuteJavaScript(string javascript, params object[] variables)
Parameters
Type Name Description
System.String javascript

The JavaScript code to execute.

System.Object[] variables

The objects to use inside the JavaScript call.

Returns
Type Description
System.IDisposable

The result, if any, of the JavaScript call.

| Improve this Doc View Source

ExecuteJavaScriptAsync(String)

Allows calling JavaScript code from within C#. The call will be asynchronous when run in the Simulator.

Declaration
public static IDisposable ExecuteJavaScriptAsync(string javascript)
Parameters
Type Name Description
System.String javascript

The JavaScript code to execute.

Returns
Type Description
System.IDisposable
| Improve this Doc View Source

ExecuteJavaScriptAsync(String, Object[])

Allows calling JavaScript code from within C#. The call will be asynchronous when run in the Simulator.

Declaration
public static IDisposable ExecuteJavaScriptAsync(string javascript, params object[] variables)
Parameters
Type Name Description
System.String javascript

The JavaScript code to execute.

System.Object[] variables

The objects to use inside the JavaScript call.

Returns
Type Description
System.IDisposable
| Improve this Doc View Source

ExecuteJavaScriptGetResult<T1>(String)

Declaration
public static T1 ExecuteJavaScriptGetResult<T1>(string javascript)
Parameters
Type Name Description
System.String javascript
Returns
Type Description
T1
Type Parameters
Name Description
T1
| Improve this Doc View Source

ExecuteJavaScriptVoid(String)

Declaration
public static void ExecuteJavaScriptVoid(string javascript)
Parameters
Type Name Description
System.String javascript
| Improve this Doc View Source

ExecuteJavaScriptVoid(String, Object[])

Declaration
public static void ExecuteJavaScriptVoid(string javascript, params object[] variables)
Parameters
Type Name Description
System.String javascript
System.Object[] variables
| Improve this Doc View Source

ExecuteJavaScriptVoidAsync(String)

Declaration
public static void ExecuteJavaScriptVoidAsync(string javascript)
Parameters
Type Name Description
System.String javascript
| Improve this Doc View Source

ExecuteJavaScriptVoidAsync(String, Object[])

Declaration
public static void ExecuteJavaScriptVoidAsync(string javascript, params object[] variables)
Parameters
Type Name Description
System.String javascript
System.Object[] variables
| Improve this Doc View Source

GetDiv(UIElement)

Returns the HTML Div that is associated to the specified FrameworkElement. Note: the FrameworkElement must be in the visual tree. Consider calling this method from the 'Loaded' event to ensure that the element is in the visual tree.

Declaration
public static object GetDiv(UIElement element)
Parameters
Type Name Description
UIElement element
Returns
Type Description
System.Object
| Improve this Doc View Source

LoadCssFile(Interop.ResourceFile)

Declaration
public static Task<object> LoadCssFile(Interop.ResourceFile resourceFile)
Parameters
Type Name Description
Interop.ResourceFile resourceFile
Returns
Type Description
System.Threading.Tasks.Task<System.Object>
| Improve this Doc View Source

LoadCssFile(String)

Adds a 'link' tag to the HTML page and waits for the CSS file to finish loading.

Declaration
public static Task<object> LoadCssFile(string url)
Parameters
Type Name Description
System.String url

The URL of the CSS file, with the syntax ms-appx:///AssemblyName/Folder/FileName.css or /AssemblyName;component/Folder/FileName.css

Returns
Type Description
System.Threading.Tasks.Task<System.Object>

Nothing

| Improve this Doc View Source

LoadCssFilesAsync(IEnumerable<Interop.ResourceFile>, Action)

Declaration
public static void LoadCssFilesAsync(IEnumerable<Interop.ResourceFile> resourceFiles, Action callback)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<Interop.ResourceFile> resourceFiles
System.Action callback
| Improve this Doc View Source

LoadCssFilesAsync(IEnumerable<String>, Action)

Adds 'link' tags to the HTML page and waits for the CSS files to finish loading.

Declaration
public static void LoadCssFilesAsync(IEnumerable<string> urls, Action callback)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<System.String> urls

The URL of the CSS files, with the syntax ms-appx:///AssemblyName/Folder/FileName.css or /AssemblyName;component/Folder/FileName.css

System.Action callback

The method that is called when the CSS files have finished loading.

| Improve this Doc View Source

LoadJavaScriptFile(Interop.ResourceFile)

Declaration
public static Task<object> LoadJavaScriptFile(Interop.ResourceFile resourceFile)
Parameters
Type Name Description
Interop.ResourceFile resourceFile
Returns
Type Description
System.Threading.Tasks.Task<System.Object>
| Improve this Doc View Source

LoadJavaScriptFile(String)

Adds a 'script' tag to the HTML page and waits for the script to finish loading.

Declaration
public static Task<object> LoadJavaScriptFile(string url)
Parameters
Type Name Description
System.String url

The URL of the JavaScript file, with the syntax ms-appx:///AssemblyName/Folder/FileName.js or /AssemblyName;component/Folder/FileName.js

Returns
Type Description
System.Threading.Tasks.Task<System.Object>

Nothing.

| Improve this Doc View Source

LoadJavaScriptFilesAsync(IEnumerable<Interop.ResourceFile>, Action, Action)

Declaration
public static void LoadJavaScriptFilesAsync(IEnumerable<Interop.ResourceFile> resourceFiles, Action callback, Action callbackOnError = null)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<Interop.ResourceFile> resourceFiles
System.Action callback
System.Action callbackOnError
| Improve this Doc View Source

LoadJavaScriptFilesAsync(IEnumerable<String>, Action, Action)

Loads a list of JavaScript files from either an online location (http/https) or the local project. Note: This method will stop at the first script it cannot load, meaning that all subsequent scripts will not be loaded.

Declaration
public static void LoadJavaScriptFilesAsync(IEnumerable<string> urls, Action callback, Action callbackOnError = null)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<System.String> urls

The URLs of the JavaScript files, with the syntax ms-appx:///AssemblyName/Folder/FileName.js or /AssemblyName;component/Folder/FileName.js or https://someAddress/FileName.js

System.Action callback

The method that is called when all the files have successfully finished loading.

System.Action callbackOnError

The method that is called when one of the files could not be loaded.

  • Improve this Doc
  • View Source