Ejemplo n.º 1
0
 /// <summary>
 /// 执行Command
 /// </summary>
 /// <param name="parameter">参数条件</param>
 public virtual void Execute(object parameter)
 {
     if (CanExecute(parameter))
     {
         OnCommandExecute(EventCommandEventArgs.Create(parameter, ViewModel));
     }
 }
Ejemplo n.º 2
0
                /// <summary>
                /// Executes from event.
                /// </summary>
                /// <param name="sender">The sender.</param>
                /// <param name="eventArgs">The event arguments.</param>
                /// <param name="eventName">Name of the event.</param>
                /// <param name="eventHandlerType">Type of the event handler.</param>
                public void ExecuteFromEvent(object sender, object eventArgs, string eventName, Type eventHandlerType)
                {
                    object vm = null;

                    var s = (sender as FrameworkElement);

                    if (Command == null)
                    {
                        return;
                    }
                    var cvm = Command as ICommandWithViewModel;

                    if (cvm != null)
                    {
                        vm = cvm.ViewModel;
                    }


                    var newe = EventCommandEventArgs.Create(Parameter, vm, sender, eventArgs, eventName, eventHandlerType);

                    if (Command.CanExecute(newe))
                    {
                        var spEventCommand = Command as EventCommandBase;
                        if (spEventCommand == null)
                        {
                            Command.Execute(newe);
                        }
                        else
                        {
                            spEventCommand.OnCommandExecute(newe);
                        }
                    }
                }
Ejemplo n.º 3
0
 /// <summary>
 /// Executes the specified parameter.
 /// </summary>
 /// <param name="parameter">The parameter.</param>
 public void Execute(object parameter)
 {
     if (CanExecute(parameter))
     {
         var evp = EventCommandEventArgs.Create(parameter, ViewModel, null);
         _executeSource.OnNext(new EventPattern <EventCommandEventArgs>(this, evp));
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Executes asynchronously.
 /// </summary>
 /// <param name="parameter">The parameter.</param>
 /// <returns></returns>
 public async Task ExecuteAsync(object parameter)
 {
     if (CanExecute(parameter))
     {
         var evp = EventCommandEventArgs.Create(parameter, ViewModel);
         _executeSource.OnNext(new EventPattern <EventCommandEventArgs>(this, evp));
         await evp.Completion.Task;
     }
 }
Ejemplo n.º 5
0
        void WireEventToItem(IApplicationBarMenuItem item)
        {
            //if (commandSubscription != null)
            //{
            //    commandSubscription.Dispose();
            //    commandSubscription = null;
            //}

            //commandSubscription =
            Observable.FromEventPattern(
                eh => item.Click += eh,
                eh => item.Click -= eh)
            .Subscribe(
                ev =>
            {
                var agg = EventCommandEventArgs.Create(AssociatedObject.CommandParameter, null, ev.Sender, ev.EventArgs, "Click", typeof(EventHandler));

                EventRouting.EventRouter.Instance
                .RaiseEvent(item, agg, EventFilterName);
            }
                );
        }