/// <summary>
 /// 执行注册的脚本行为
 /// </summary>
 /// <param name="actionName"></param>
 /// <param name="arg"></param>
 /// <returns></returns>
 internal bool CallRegisteredScriptAction(string actionName, ScriptView arg, ref IScriptView returnValue)
 {
     if (_registeredScriptActions != null)
     {
         Func <ScriptView, IScriptView> action = null;
         if (_registeredScriptActions.TryGetValue(actionName, out action))
         {
             returnValue = action(arg);
             return(true);
         }
     }
     return(false);
 }
Beispiel #2
0
        /// <summary>
        /// 绘制脚本回调
        /// </summary>
        public void DrawScriptCallback(IScriptView view)
        {
            var output = view.Output();

            using (var temp = StringPool.Borrow())
            {
                StringBuilder code = temp.Item;
                code.Append("<script>$(document).ready(function () { ");
                code.AppendFormat("$$view.callback({0});", output.GetCode());
                code.Append(" });</script>");
                this.DrawLine(code.ToString(), DrawOrigin.Bottom);
            }
        }
        private static object ExecuteAction(UIElement e, string actionName, ScriptView arg)
        {
            IScriptView result = null;

            if (e.CallRegisteredScriptAction(actionName, arg, ref result))
            {
                return(result);                                                           //优先执行注册的行为
            }
            var action = e.ObjectType.ResolveMethod(actionName, ActionParameters);

            if (action != null)
            {
                using (var temp = ArgsPool.Borrow1())
                {
                    var args = temp.Item;
                    args[0] = arg;
                    return(action.Invoke(e, args));
                }
            }

            return(null);

            //IScriptView result = null;
            //if (e.CallRegisteredScriptAction(actionName, arg, ref result)) return result; //优先执行注册的行为
            //var action = DependencyAction.GetAction(e.ObjectType, actionName);
            //if (action != null)
            //{
            //    if (!action.AllowClientAccess) throw new XamlException("组件方法" + actionName + "未公开");
            //    return e.CallAction(action, arg);
            //}

            ////如果未能成功在e上执行行文,那么找父亲对象的方法
            //var parent = e.Parent as UIElement;
            //if (parent != null) return parent.CallScriptAction(null, actionName, arg);

            //throw new XamlException("未能执行" + actionName);
        }