コード例 #1
0
ファイル: XToggleButton.cs プロジェクト: windygu/Controls
        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
ファイル: XComboBox.cs プロジェクト: windygu/Controls
 protected override void OnSelectionChanged(SelectionChangedEventArgs e)
 {
     base.OnSelectionChanged(e);
     if (!IsCommandExecuting)
     {
         try
         {
             IsCommandExecuting = true;
             CommandUtil.Execute(this);
         }
         finally { IsCommandExecuting = false; }
     }
 }
コード例 #3
0
ファイル: XComboBox.cs プロジェクト: windygu/Controls
        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; }
            }
        }
コード例 #4
0
        public static void IntializeCommandBindings(BaseRichTextBox richTextBox)
        {
            if (richTextBox == null)
            {
                return;
            }

            richTextBox.CommandBindings.Add(new BaseCommandBinding(
                                                EditingCommands.ToggleBold,
                                                (sender, e) => SetBold(richTextBox, !GetBold(richTextBox)),
                                                (sender, e) =>
            {
                CommandUtil.SetCurrentValue(e, GetBold(richTextBox));

                e.CanExecute = true;
                e.Handled    = true;
            }, richTextBox));

            richTextBox.CommandBindings.Add(new BaseCommandBinding(
                                                EditingCommands.ToggleItalic,
                                                (sender, e) => SetItalic(richTextBox, !GetItalic(richTextBox)),
                                                (sender, e) =>
            {
                CommandUtil.SetCurrentValue(e, GetItalic(richTextBox));

                e.CanExecute = true;
                e.Handled    = true;
            }, richTextBox));
            richTextBox.CommandBindings.Add(new BaseCommandBinding(
                                                EditingCommands.ToggleUnderline,
                                                (sender, e) => SetUnderline(richTextBox, !GetUnderline(richTextBox)),
                                                (sender, e) =>
            {
                CommandUtil.SetCurrentValue(e, GetUnderline(richTextBox));

                e.CanExecute = true;
                e.Handled    = true;
            }, richTextBox));
            richTextBox.CommandBindings.Add(new BaseCommandBinding(
                                                EditingCommands.AlignLeft,
                                                (sender, e) => SetAlignLeft(richTextBox, !GetAlignLeft(richTextBox)),
                                                (sender, e) =>
            {
                CommandUtil.SetCurrentValue(e, GetAlignLeft(richTextBox));

                e.CanExecute = true;
                e.Handled    = true;
            }, richTextBox));
            richTextBox.CommandBindings.Add(new BaseCommandBinding(
                                                EditingCommands.AlignCenter,
                                                (sender, e) => SetAlignCenter(richTextBox, !GetAlignCenter(richTextBox)),
                                                (sender, e) =>
            {
                CommandUtil.SetCurrentValue(e, GetAlignCenter(richTextBox));

                e.CanExecute = true;
                e.Handled    = true;
            }, richTextBox));
            richTextBox.CommandBindings.Add(new BaseCommandBinding(
                                                EditingCommands.AlignRight,
                                                (sender, e) => SetAlignRight(richTextBox, !GetAlignRight(richTextBox)),
                                                (sender, e) =>
            {
                CommandUtil.SetCurrentValue(e, GetAlignRight(richTextBox));

                e.CanExecute = true;
                e.Handled    = true;
            }, richTextBox));
            richTextBox.CommandBindings.Add(new BaseCommandBinding(
                                                EditingCommands.AlignJustify,
                                                (sender, e) => SetAlignJustify(richTextBox, !GetAlignJustify(richTextBox)),
                                                (sender, e) =>
            {
                CommandUtil.SetCurrentValue(e, GetAlignJustify(richTextBox));

                e.CanExecute = true;
                e.Handled    = true;
            }, richTextBox));
            richTextBox.CommandBindings.Add(new BaseCommandBinding(
                                                MyCommands.SetFontSize,
                                                (sender, e) =>
            {
                if (e.Parameter is double)
                {
                    SetFontSize(richTextBox, (double)e.Parameter);
                }
            },
                                                (sender, e) =>
            {
                CommandUtil.SetCurrentValue(e, GetFontSize(richTextBox));
                e.CanExecute = true;
                e.Handled    = true;
            }, richTextBox));
            richTextBox.CommandBindings.Add(new BaseCommandBinding(
                                                MyCommands.SetFontFamily,
                                                (sender, e) =>

            {
                if (e.Parameter is FontFamily)
                {
                    SetFontFamily(richTextBox, (FontFamily)e.Parameter);
                }
            },
                                                (sender, e) =>
            {
                CommandUtil.SetCurrentValue(e, GetFontFamily(richTextBox));
                e.CanExecute = true;
                e.Handled    = true;
            }, richTextBox));
            //richTextBox.CommandBindings.Add(new CommandBinding(
            //                                    MyCommands.SetFontColor,
            //                                    (sender, e) =>
            //                                    {
            //                                        if (e.Parameter is Color)
            //                                        {
            //                                            SetFontColor(richTextBox, (Color)e.Parameter);
            //                                        }
            //                                    },
            //                                    (sender, e) =>
            //                                    {
            //                                        CommandUtil.SetCurrentValue(e, GetFontColor(richTextBox));
            //                                        e.CanExecute = true;
            //                                        e.Handled = true;
            //                                    }));
        }