Beispiel #1
0
 public BaseCommandBinding(ICommand command, ExecutedRoutedEventHandler executed, CanExecuteRoutedEventHandler canExecute, BaseRichTextBox richTextBox)
     : base(command, executed, canExecute)
 {
     Element   = richTextBox;
     Executed -= Element.OnCommandExecuted;
     Executed += Element.OnCommandExecuted;
 }
Beispiel #2
0
 public static void SelectAll(string file, BaseRichTextBox control)
 {
     new TextRange
         (control.Document.ContentStart, control.Document.ContentEnd)
     .ApplyPropertyValue(TextElement.BackgroundProperty, Brushes.White);
     foreach (var item in rezults)
     {
         if (item.Path == file)
         {
             new TextRange(control.Document.ContentStart.GetPositionAtOffset(item.Start), control.Document.ContentStart.GetPositionAtOffset(item.End)).
             ApplyPropertyValue(TextElement.BackgroundProperty, Brushes.Yellow);
         }
     }
 }
Beispiel #3
0
        public static void ClearAll(BaseRichTextBox control)
        {
            var list = rezults.GroupBy(item => item.Path).ToList();

            foreach (var item in list)
            {
                var range = item.ToList();
                if (!range.Any())
                {
                    continue;
                }
                string path = range[0].Path;
                range.ForEach(x => rezults.Remove(x));
            }
        }
        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;
            //                                    }));
        }