This is a migrated thread and some comments may be shown as answers.

[Solved] Problem with spellchecker suggestions in RadRichTextBoxes using custom ContextMenuContentBuilder

1 Answer 85 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Peter
Top achievements
Rank 1
Peter asked on 04 Feb 2011, 06:02 PM
I have more than one RadRichTextBox with spellchecking turned on in a grid and I am providing my own ContextMenuContentBuilder.  When I highlight a misspelled word in the first RadRichTextBox and choose a suggestion from the context menu, the word is corrected but only the first letter of the word is displayed.  Subsequent clicking on the word causes a crash (Object reference not set to an instance of an object).  I have pasted in the MainPage of the project below to reproduce the bug.  Have I done something incorrectly?  If not, are there any workarounds available?  If no workarounds, will there be a fix soon?  Thanks.

public partial class MainPage : UserControl
    {
        public class CustomContextMenuContentBuilder : ContextMenuContentBuilder
        {
            public CustomContextMenuContentBuilder(RadRichTextBox richTextBox)
                : base(richTextBox)
            {
            }
        }
  
        public MainPage()
        {
            InitializeComponent();
  
            LayoutRoot.Children.Add(CreateRichTextControls(0, 0));
            LayoutRoot.Children.Add(CreateRichTextControls(1, 1));
        }
  
        private RadRichTextBox CreateRichTextControls(int row, int col)
        {
            RadRichTextBox control = new RadRichTextBox();
            control.HorizontalAlignment = HorizontalAlignment.Stretch;
            control.VerticalAlignment = VerticalAlignment.Stretch;
            control.Background = new SolidColorBrush(Colors.LightGray);
  
            control.SetValue(Grid.RowProperty, row);
            control.SetValue(Grid.ColumnProperty, col);
  
            Telerik.Windows.Controls.RichTextBoxUI.ContextMenu contextMenu = (Telerik.Windows.Controls.RichTextBoxUI.ContextMenu)control.ContextMenu;
            contextMenu.ContentBuilder = new CustomContextMenuContentBuilder(control);
  
            return control;
        }
    }

1 Answer, 1 is accepted

Sort by
0
Boby
Telerik team
answered on 09 Feb 2011, 01:10 PM
Hello Peter,
Thank you for this excellent report. The incorrect behavior is caused by the fact that context menu is loaded by MEF - this makes one ContextMenu instance shared between multiple RadRichTextBoxes,  causing context menu's CustomContextMenuContentBuilder to be associated with the second RadRichTextBox. This is considered a bug, and hopefully will be fixed in next major release.
As a simple workaround, you can instantiate your context menus manually and do not rely on MEF:
private RadRichTextBox CreateRichTextControls(int row, int col)
{
    RadRichTextBox control = new RadRichTextBox();
    control.HorizontalAlignment = HorizontalAlignment.Stretch;
    control.VerticalAlignment = VerticalAlignment.Stretch;
    control.Background = new SolidColorBrush(Colors.LightGray);
 
    control.SetValue(Grid.RowProperty, row);
    control.SetValue(Grid.ColumnProperty, col);
 
    ContextMenu contextMenu = new ContextMenu();
    contextMenu.ContentBuilder = new CustomContextMenuContentBuilder(control);
 
    control.ContextMenu = contextMenu;
 
    return control;
}

We have added Telerik points to your account in appreciation. Don't hesitate to contact us if you have other questions.


Best wishes,
Boby
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
Tags
RichTextBox
Asked by
Peter
Top achievements
Rank 1
Answers by
Boby
Telerik team
Share this question
or