Esempio n. 1
0
        private ICommand CreateRoutingCommand()
        {
            if (Command != null && MultipleCommand != null)
            {
                var command = new DelegateCommand <object>(o =>
                {
                    if (o is TItem item)
                    {
                        Command.Execute(item);
                    }
                    else if (o is IList list)
                    {
                        if (list.Count == 1)
                        {
                            Command.Execute(list.Cast <TItem>().Single());
                        }
                        else
                        {
                            MultipleCommand.Execute(list.Cast <TItem>().ToList());
                        }
                    }
                }, o =>
                {
                    if (o is TItem item)
                    {
                        return(Command.CanExecute(item));
                    }
                    if (o is IList list)
                    {
                        if (list.Count == 1)
                        {
                            return(Command.CanExecute(list.Cast <TItem>().Single()));
                        }
                        else
                        {
                            return(MultipleCommand.CanExecute(list.Cast <TItem>().ToList()));
                        }
                    }

                    return(true);
                });

                Command.CanExecuteChanged         += (sender, args) => command.RaiseCanExecuteChanged();
                MultipleCommand.CanExecuteChanged += (sender, args) => command.RaiseCanExecuteChanged();
                return(command);
            }

            if (MultipleCommand != null)
            {
                var command = new DelegateCommand <IList>(list => MultipleCommand.Execute(list.Cast <TItem>().ToList()),
                                                          list => MultipleCommand.CanExecute(list.Cast <TItem>().ToList()));
                MultipleCommand.CanExecuteChanged += (sender, args) => command.RaiseCanExecuteChanged();
                return(command);
            }

            return(Command);
        }
Esempio n. 2
0
        private ICommand CreateRoutingCommand()
        {
            if (Command != null && MultipleCommand != null)
            {
                ContextAwareDelegateCommand <object> command = null;
                command = new ContextAwareDelegateCommand <object>(o =>
                {
                    if (o is TItem item)
                    {
                        Command.Execute(item, (TContext)command.Context);
                    }
                    else if (o is IList list)
                    {
                        if (list.Count == 1)
                        {
                            Command.Execute(list.Cast <TItem>().Single(), (TContext)command.Context);
                        }
                        else
                        {
                            MultipleCommand.Execute(list.Cast <TItemBase>(), (TContext)command.Context);
                        }
                    }
                }, o =>
                {
                    if (o is TItem item)
                    {
                        return(Command.CanExecute(item, (TContext)command.Context));
                    }
                    if (o is IList list)
                    {
                        if (list.Count == 1)
                        {
                            return(Command.CanExecute(list.Cast <TItem>().Single(), (TContext)command.Context));
                        }
                        else
                        {
                            return(MultipleCommand.CanExecute(list.Cast <TItemBase>(), (TContext)command.Context));
                        }
                    }

                    return(true);
                });

                Command.CanExecuteChanged         += (sender, args) => command.RaiseCanExecuteChanged();
                MultipleCommand.CanExecuteChanged += (sender, args) => command.RaiseCanExecuteChanged();
                return(command);
            }

            if (MultipleCommand != null)
            {
                ContextAwareDelegateCommand <IList> command = null;
                command = new ContextAwareDelegateCommand <IList>(
                    list => MultipleCommand.Execute(list.Cast <TItemBase>(), (TContext)command.Context),
                    list => MultipleCommand.CanExecute(list.Cast <TItemBase>(), (TContext)command.Context));
                MultipleCommand.CanExecuteChanged += (sender, args) => command.RaiseCanExecuteChanged();
                return(command);
            }
            else
            {
                ContextAwareDelegateCommand <object> command = null;
                command = new ContextAwareDelegateCommand <object>(
                    o => Command.Execute((TItem)o, (TContext)command.Context),
                    o => Command.CanExecute((TItem)o, (TContext)command.Context));
                return(command);
            }
        }
Esempio n. 3
0
 private void button8_Click(object sender, EventArgs e)
 {
     MultipleCommand.ResetText();
 }