public void Search(string searchTerm)
        {
            NoteEditorSearchHighlight.Clear();

            if (String.IsNullOrEmpty(searchTerm) == true)
            {
                return;
            }

            TextRange textRange = FindText(Document.ContentStart, Document.ContentEnd, searchTerm);

            if (textRange == null)
            {
                return;
            }

            // bring the first search result in the view
            if (textRange.Start.Paragraph is FrameworkContentElement fce)
            {
                fce.BringIntoView();
            }

            // search for the next matches until end of document
            while (textRange != null)
            {
                NoteEditorSearchHighlight.Add(textRange, false); // do not update adorner layout while adding search results
                textRange = FindText(textRange.End, Document.ContentEnd, searchTerm);
            }

            NoteEditorSearchHighlight.Update();
        }
Exemple #2
0
        public NoteEditor()
        {
            // event handlers
            TextChanged      += OnTextChanged;
            PreviewKeyDown   += OnPreviewKeyDown;
            PreviewMouseDown += OnPreviewMouseDown; // PreviewMouseDown for image resize adorner

            // Credit: http://social.msdn.microsoft.com/Forums/vstudio/en-US/0d672c70-d49d-4ebf-871d-420cc164f7d8/c-wpf-richtextbox-remove-formatting-and-line-spaces
            DataObject.AddPastingHandler(this, DataObjectPastingEventHandler);

            // add custom binding for Ctrl+Shift+V for rich format pasting
            InputBindings.Add(new KeyBinding(ApplicationCommands.Paste, Key.V, ModifierKeys.Control | ModifierKeys.Shift));

            // search results highlight support
            NoteEditorSearchHighlight.Init(this);

            // image resize support
            ImageResizeHelper.Init(this);

            // register global commands
            CommandManager.RegisterClassCommandBinding(typeof(Window), new CommandBinding(FontStylesCommand, OnFontStylesCommand, CanExecuteFontStylesCommand));
            CommandManager.RegisterClassCommandBinding(typeof(Window), new CommandBinding(ParagraphStylesCommand, OnParagraphStylesCommand, CanExecuteParagraphStylesCommand));
        }