示例#1
0
        private void UpdateCanExecute()
        {
            if (IsCommandExecuting)
            {
                return;
            }

            IsCommandExecuting = true;
            try
            {
                //use our custom class as the parameter
                var parameter = new CommandCanExecuteParameter(null);
                CommandUtil.CanExecute(this, parameter);
                //we set the current status independent on whether the command can execute
                {
                    if (parameter.CurrentValue is bool)
                    {
                        IsChecked = (bool)parameter.CurrentValue;
                    }
                    else
                    {
                        IsChecked = false;
                    }
                }
            }
            finally
            {
                IsCommandExecuting = false;
            }
        }
示例#2
0
        protected virtual void UpdateCanExecute()
        {
            if (IsCommandExecuting)
            {
                return;
            }

            ICommand cmd = Command;

            if (cmd == null)
            {
                IsEnabled = true;
            }
            else
            {
                try
                {
                    IsCommandExecuting = true;

                    IsEnabled = CommandUtil.CanExecute(this, CommandParameter);
                    var ca = new CommandCanExecuteParameter(CommandParameter);
                    CommandUtil.CanExecute(this, ca);
                    object value = ca.CurrentValue;

                    //if (value is RangedValue)
                    //	value = ((RangedValue) value).Value;

                    object o = FindItemByData(value);

                    if (o == null && value == null)
                    {
                        Text         = null;
                        SelectedItem = null;
                    }
                    else if (o != null && !Equals(SelectedItem, o))
                    {
                        SelectedItem = o;
                    }
                    else if (IsEditable && !IsReadOnly &&
                             value != null && Text != value.ToString())
                    {
                        Text = value.ToString();
                    }
                }
                finally { IsCommandExecuting = false; }
            }
        }