Example #1
0
        /// <summary>
        ///     Attaches a FormatBar to a RichtextBox
        /// </summary>
        /// <param name="richTextBox">The RichtextBox to attach to.</param>
        /// <param name="formatBar">The Formatbar to attach.</param>
        private void AttachFormatBarToRichtextBox(System.Windows.Controls.RichTextBox richTextBox,
                                                  IRichTextBoxFormatBar formatBar)
        {
            _richTextBox = richTextBox;
            //we cannot use the PreviewMouseLeftButtonUp event because of selection bugs.
            //we cannot use the MouseLeftButtonUp event because it is handled by the RichTextBox and does not bubble up to here, so we must
            //add a hander to the MouseUpEvent using the Addhandler syntax, and specify to listen for handled events too.
            _richTextBox.AddHandler(Mouse.MouseUpEvent, new MouseButtonEventHandler(RichTextBox_MouseButtonUp), true);
            _richTextBox.TextChanged += RichTextBox_TextChanged;

            _adorner = new UIElementAdorner <Control>(_richTextBox);

            formatBar.Target = _richTextBox;
            _toolbar         = formatBar;
        }