This is a migrated thread and some comments may be shown as answers.
Multiple RichTextBoxes Paste Error
2 Answers 16 Views
This is a migrated thread and some comments may be shown as answers.
Anthony
Top achievements
Rank 2
Anthony asked on 23 Nov 2012, 09:24 PM

I've run in to some strange behaviour when I have two or more RadRichTextBoxes on the screen at the same time while using a custom ContextMenuContentBuilder. When I click on Paste from the context menu of any of the RadRichTextBoxes it pastes in the last one rendered. However if I paste using CTRL+V it works properly. I'm guessing I've implemented something wrong here but can't quite figure out what.

Here is the code:
MainPage.xaml

<Grid x:Name="LayoutRoot" Background="White">
    <StackPanel>
        <telerik:RadRichTextBox Height="100" x:Name="RadRichTextBox1">
        </telerik:RadRichTextBox>
        <telerik:RadRichTextBox Height="100" x:Name="RadRichTextBox2">
        </telerik:RadRichTextBox>
 
    </StackPanel>
</Grid>

MainPage.xaml.cs

public partial class MainPage : UserControl
{
    public MainPage()
    {
        InitializeComponent();
        Loaded += new RoutedEventHandler(MainPage_Loaded);
    }
 
    void MainPage_Loaded(object sender, RoutedEventArgs e)
    {
        if (!DesignerProperties.IsInDesignTool)
        {
            ContextMenu contextMenu1 = (ContextMenu)RadRichTextBox1.ContextMenu;
            contextMenu1.ContentBuilder = new TextMenuBuilder(RadRichTextBox1);
 
            ContextMenu contextMenu2 = (ContextMenu)RadRichTextBox2.ContextMenu;
            contextMenu2.ContentBuilder = new TextMenuBuilder(RadRichTextBox2);
        }
 
    }
}

TextMenuBuilder.cs

public class TextMenuBuilder:ContextMenuContentBuilder
{
    private RadRichTextBox radRichTextBox;
    public TextMenuBuilder(RadRichTextBox radRichTextBox)
        :base(radRichTextBox)
    {
        this.radRichTextBox = radRichTextBox;
    }
}

By the way, I've taken all of my custom code out of the TextMenuBuilder class in an attempt to isolate the issue - I am planning to add custom menu items to each of the different RadRichTextBoxes.

Thanks,
Anthony

2 Answers, 1 is accepted

Sort by
0
Accepted
Boby
Telerik team
answered on 26 Nov 2012, 09:51 AM
Hello Anthony,
The behavior you are observing is due to the fact that by default ContextMenu instance is shared between all the RadRichTextBoxes. You can easily change the default context menu by  declaring non-sharable custom menu and mark it with CustomContextMenuAttribute, so that RadRichTextBoxes could automatically load it:
[PartCreationPolicy(CreationPolicy.NonShared)]
[CustomContextMenu]
public class NonSharedContextMenu : ContextMenu
{
 
}

Don't hesitate to contact us if you have further questions.



All the best,
Boby
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Anthony
Top achievements
Rank 2
answered on 26 Nov 2012, 01:37 PM
Thanks Boby,

I was hoping it was something simple like that! It worked perfectly!

Thanks,
Anthony
Asked by
Anthony
Top achievements
Rank 2
Answers by
Boby
Telerik team
Anthony
Top achievements
Rank 2
Share this question
or