示例#1
0
        private void InitCommands()
        {
            #region Commands

            _addDataEntityCommand = new AddDataEntityCommand()
            {
                //这里设置CanExcute是因为工具栏也要用这个Command,而工具栏上的添加按钮是共用于添加实体和项两种情况的
                CanExcuteHandler = () =>
                {
                    return(_controller.CurrentType == typeof(DataEntityDev));
                }
            };
            _editDataEntityCommand = new EditDataEntityCommand()
            {
                CanExcuteHandler = () =>
                {
                    return(_controller.SelectedItemsCount == 1 &&
                           _controller.GetSelectedItem <DataEntityDev>() != null);
                },
                GetArgumentHandler = () => { return(_controller.GetSelectedItem <DataEntityDev>()); }
            };
            _deleteDataEntityCommand = new DeleteDataEntityCommand()
            {
                CanExcuteHandler   = () => { return(_controller.GetSelectedItems <DataEntityDev>().Count > 0); },
                GetArgumentHandler = () => { return(_controller.GetSelectedItems <DataEntityDev>()); }
            };
            _createSqlCommand = new CreateSqlCommand()
            {
                CanExcuteHandler   = () => { return(_controller.GetSelectedItems <DataEntityDev>().Count > 0); },
                GetArgumentHandler = () => { return(_controller.GetSelectedItems <DataEntity>()); }
            };

            _addDataItemEntityCommand = new AddDataItemEntityCommand()
            {
                //这里拿数据实体DataEntityDev对象, 通过_gridViewController的上下文
                CanExcuteHandler   = () => { return(_controller.GetContextData <DataEntityDev>() != null); },
                GetArgumentHandler = () => { return(_controller.GetContextData <DataEntityDev>()); }
            };
            _editDataItemEntityCommand = new EditDataItemEntityCommand()
            {
                CanExcuteHandler = () =>
                {
                    return(_controller.SelectedItemsCount == 1 &&
                           _controller.GetSelectedItem <DataItemEntityDev>() != null);
                },
                GetArgumentHandler = () => { return(_controller.GetSelectedItem <DataItemEntityDev>()); }
            };
            _deleteDataItemEntityCommand = new DeleteDataItemEntityCommand()
            {
                CanExcuteHandler   = () => { return(_controller.GetSelectedItems <DataItemEntityDev>().Count > 0); },
                GetArgumentHandler = () => { return(_controller.GetSelectedItems <DataItemEntityDev>()); }
            };

            #endregion
        }
        private void InitCommands()
        {
            #region Commands

            _addDataEntityCommand  = new AddDataEntityCommand();
            _editDataEntityCommand = new EditDataEntityCommand()
            {
                CanExcuteHandler = () =>
                {
                    return(_navigationTreeController.GetSelectedData <DataEntityDev>() != null);
                },
                GetArgumentHandler = () => { return(_navigationTreeController.GetSelectedData <DataEntityDev>()); }
            };
            _deleteDataEntityCommand = new DeleteDataEntityCommand()
            {
                CanExcuteHandler = () =>
                {
                    return(_navigationTreeController.GetSelectedData <DataEntityDev>() != null);
                },
                GetArgumentHandler = () =>
                {
                    return(new List <DataEntityDev>()
                    {
                        _navigationTreeController.GetSelectedData <DataEntityDev>()
                    });
                }
            };
            _createSqlCommand = new CreateSqlCommand()
            {
                CanExcuteHandler = () =>
                {
                    return(_navigationTreeController.GetSelectedData <DataEntityDev>() != null);
                },
                GetArgumentHandler = () =>
                {
                    return(new List <DataEntity>()
                    {
                        _navigationTreeController.GetSelectedData <DataEntityDev>()
                    });
                }
            };

            _addDataItemEntityCommand = new AddDataItemEntityCommand()
            {
                CanExcuteHandler = () =>
                {
                    return(_navigationTreeController.GetSelectedData <DataEntityDev>(true) != null);
                },
                GetArgumentHandler = () =>
                {
                    return(_navigationTreeController.GetSelectedData <DataEntityDev>(true));
                }
            };
            _editDataItemEntityCommand = new EditDataItemEntityCommand()
            {
                CanExcuteHandler = () =>
                {
                    return(_navigationTreeController.GetSelectedData <DataItemEntityDev>() != null);
                },
                GetArgumentHandler = () => { return(_navigationTreeController.GetSelectedData <DataItemEntityDev>()); }
            };
            _deleteDataItemEntityCommand = new DeleteDataItemEntityCommand()
            {
                CanExcuteHandler = () =>
                {
                    return(_navigationTreeController.GetSelectedData <DataItemEntityDev>() != null);
                },
                GetArgumentHandler = () =>
                {
                    return(new List <DataItemEntityDev>()
                    {
                        _navigationTreeController.GetSelectedData <DataItemEntityDev>()
                    });
                }
            };

            #endregion
        }