Class Interop
Provides static methods for executing JavaScript code from within C#.
Inheritance
Inherited Members
Namespace: OpenSilver
Assembly: OpenSilver.dll
Syntax
public static class Interop
Properties
| Improve this Doc View SourceIsRunningInTheSimulator
Returns True is the app is running in C#, and False otherwise. To know if you're in the simulator use IsRunningInTheSimulator_WorkAround.
Declaration
public static bool IsRunningInTheSimulator { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
IsRunningInTheSimulator_WorkAround
Returns True is the app is running inside the Simulator, and False otherwise.
Declaration
public static bool IsRunningInTheSimulator_WorkAround { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Methods
| Improve this Doc View SourceExecuteJavaScript(String)
Allows calling JavaScript code from within C#.
Declaration
public static object ExecuteJavaScript(string javascript)
Parameters
Type | Name | Description |
---|---|---|
System.String | javascript | The JavaScript code to execute. |
Returns
Type | Description |
---|---|
System.Object | The result, if any, of the JavaScript call. |
ExecuteJavaScript(String, Object[])
Allows calling JavaScript code from within C#.
Declaration
public static object 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.Object | The result, if any, of the JavaScript call. |
ExecuteJavaScriptAsync(String)
Allows calling JavaScript code from within C#. The call will be asynchronous when run in the Simulator.
Declaration
public static object ExecuteJavaScriptAsync(string javascript)
Parameters
Type | Name | Description |
---|---|---|
System.String | javascript | The JavaScript code to execute. |
Returns
Type | Description |
---|---|
System.Object |
ExecuteJavaScriptAsync(String, Object[])
Allows calling JavaScript code from within C#. The call will be asynchronous when run in the Simulator.
Declaration
public static object 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.Object |
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 |
IsNull(Object)
Check if the given jsnode is undefined
Declaration
public static bool IsNull(object jsObject)
Parameters
Type | Name | Description |
---|---|---|
System.Object | jsObject |
Returns
Type | Description |
---|---|
System.Boolean |
IsUndefined(Object)
Check if the given jsnode is undefined
Declaration
public static bool IsUndefined(object jsObject)
Parameters
Type | Name | Description |
---|---|---|
System.Object | jsObject |
Returns
Type | Description |
---|---|
System.Boolean |
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> |
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 |
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 |
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. |
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> |
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. |
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 |
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. |
Unbox(Object)
Unboxes the value passed as a parameter. It is particularly useful for the variables of the ExecuteJavaScript Methods calls aimed at using third party libraries.
Declaration
public static object Unbox(object value)
Parameters
Type | Name | Description |
---|---|---|
System.Object | value | The value to unbox. |
Returns
Type | Description |
---|---|
System.Object | the unboxed value if the value was boxed, the value itself otherwise. |