当前位置: 首页>>代码示例>>C#>>正文


C# WebControl.CreateGlobalJavascriptObject方法代码示例

本文整理汇总了C#中WebControl.CreateGlobalJavascriptObject方法的典型用法代码示例。如果您正苦于以下问题:C# WebControl.CreateGlobalJavascriptObject方法的具体用法?C# WebControl.CreateGlobalJavascriptObject怎么用?C# WebControl.CreateGlobalJavascriptObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WebControl的用法示例。


在下文中一共展示了WebControl.CreateGlobalJavascriptObject方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BindAPIFunctions

        /// <summary>
        /// Helper function to bind the API functions to a web control.
        /// </summary>
        /// <param name="pControl">The web control to bind the functions too.</param>
        private void BindAPIFunctions(WebControl pControl)
        {
            // Create and acquire a global Javascript object - this will persist for the lifetime of the web-view.
            using (JSObject pAuthority = pControl.CreateGlobalJavascriptObject(Authority.APIObject_Authority))
            {
                // Handle requests for Authority.request.
                pAuthority.Bind(Authority.APIObject_AuthorityRequest, false, (s, e) =>
                {
                    // Process the arguments.
                    var sHandler = (e.Arguments.Length > 0 && e.Arguments[0].IsString) ? ((String)e.Arguments[0]) : null;
                    var dObject = (e.Arguments.Length > 1 && e.Arguments[1].IsObject) ? e.Arguments[1] : new JSValue();

                    // Return the result.
                    var bResult = Authority.ProcessRequest(this, this.ActiveSurface, sHandler, dObject);
                    //e.Result = new JSValue(bResult);
                });

                // Handle requests for Authority.request.
                pAuthority.Bind(Authority.APIObject_AuthorityCall, false, (s, e) =>
                {
                    // Process the arguments.
                    var sTargetSurface = (e.Arguments.Length > 0 && e.Arguments[0].IsString) ? ((String)e.Arguments[0]) : null;
                    var sTargetFunction = (e.Arguments.Length > 1 && e.Arguments[1].IsString) ? ((String)e.Arguments[1]) : null;
                    //var dObject = (e.Arguments.Length > 2 && e.Arguments[2].IsObject) ? e.Arguments[2] : new JSValue();

                    List<JSValue> lArgs = new List<JSValue>();
                    for (int iArg = 2; iArg < e.Arguments.Length; ++iArg)
                    {
                        lArgs.Add(e.Arguments[iArg]);
                    }

                    // Return the result.
                    var bResult = Authority.ProcessRMICall(this, this.ActiveSurface, sTargetSurface, sTargetFunction, lArgs.ToArray());
                    //e.Result = new JSValue(bResult);
                });

                // Handle requests for Authority.request.
                pAuthority.Bind(Authority.APIObject_AuthorityLog, false, (s, e) =>
                {
                    // Process the arguments.
                    StringBuilder sOut = new StringBuilder();
                    for (int iArg = 0; iArg < e.Arguments.Length; ++iArg)
                    {
                        sOut.Append(ToJSON(e.Arguments[iArg]));

                        if (iArg < (e.Arguments.Length-1))
                            sOut.Append(" --- ");   
                    }

                    // Return the result.
                    Log.Write("JS Message: " + sOut.ToString(), this.ToString(), Log.Type.DisplayInfo);
                });
            }

            // Create a surface object.
            using (JSObject pSurface = pControl.CreateGlobalJavascriptObject(Authority.APIObject_Surface))
            {
                pSurface["Name"] = new JSValue(ActiveSurface.Identifier);
                pSurface["Width"] = new JSValue(ActiveSurface.Width);
                pSurface["Height"] = new JSValue(ActiveSurface.Height);
                pSurface["AspectRatio"] = new JSValue(ActiveSurface.AspectRatio);
                pSurface["Angle"] = new JSValue(ActiveSurface.Angle);
            }

            // Signal that the properties have changed too.
            //SignalSurfacePropertiesChanged();
        }
开发者ID:iNabarawy,项目名称:ubidisplays,代码行数:71,代码来源:Display.cs


注:本文中的WebControl.CreateGlobalJavascriptObject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。