Exemplo n.º 1
0
        public void Execute(object parameter)
        {
            if (!string.IsNullOrEmpty(CaliburnAction))
            {
                var methodName = CaliburnAction;
                if (methodName.EndsWith(""))
                {
                    methodName = methodName.Remove(methodName.Length - 2);
                }

                // will be overridden by Caliburn.
                var controls = MetaActionManager.Instance.GetControls(this);
                var source   = controls.First();

                var trigger = Parser.Parse(source, CaliburnAction).FirstOrDefault();
                var action  = trigger.Actions.OfType <ActionMessage>().FirstOrDefault();

                var context = new ActionExecutionContext
                {
                    EventArgs = new EventArgs(),
                    Message   = action,
                    Source    = source,
                };
                ActionMessage.PrepareContext(context);

                if (context.CanExecute == null || context.CanExecute())
                {
                    ActionMessage.InvokeAction(context);
                }
            }
        }
Exemplo n.º 2
0
        public static void Bind(MethodInfo method, FrameworkElement element)
        {
            var keydown = Observable.FromEventPattern <KeyEventArgs>(element, "KeyDown")
                          .Where(a => a.EventArgs.Key == Key.Return &&
                                 !a.EventArgs.Handled &&
                                 ((DataGrid)a.Sender).SelectedItem != null)
                          .Do(a => a.EventArgs.Handled = true)
                          .Select(a => ((DataGrid)a.Sender).SelectedItem);

            var mouseDoubleClick = Observable.FromEventPattern <MouseButtonEventArgs>(element, "MouseDoubleClick")
                                   .Select(a => ((DependencyObject)a.EventArgs.OriginalSource)
                                           .Parents <DataGridCell>().FirstOrDefault());

            keydown.Merge(mouseDoubleClick).Where(i => i != null)
            .CatchSubscribe(_ => {
                var context = new ActionExecutionContext {
                    Method  = method,
                    Source  = element,
                    Message = new ActionMessage {
                        MethodName = method.Name,
                    }
                };
                ActionMessage.PrepareContext(context);
                ActionMessage.InvokeAction(context);
            });
        }
Exemplo n.º 3
0
            protected override void Invoke(object parameter)
            {
                var context = new ActionExecutionContext
                {
                    Target  = _handler,
                    Message = new ActionMessage {
                        MethodName = "Execute"
                    },
                    Method = _handler.GetType().GetMethod("Execute")
                };

                ActionMessage.PrepareContext(context);

                if (context.CanExecute())
                {
                    ActionMessage.InvokeAction(context);
                }
            }
Exemplo n.º 4
0
            protected override void Invoke(object parameter)
            {
                throw new NotImplementedException();
#warning Invoke
#if false
                var context = new ActionExecutionContext
                {
                    Target  = _handler,
                    Message = new ActionMessage {
                        MethodName = "Execute"
                    },
                    Method = _handler.GetType().GetMethod("Execute")
                };
                ActionMessage.PrepareContext(context);

                if (context.CanExecute())
                {
                    ActionMessage.InvokeAction(context);
                }
#endif
            }