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

Is it possible to bind a radrichtextbox command to it's context menu?

2 Answers 209 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 15 Oct 2010, 08:46 PM
I've been working on a text editor for a website using the radrichtextbox.  I have the radrichtextboxribbonui in place and working spectacularly, as well as a radMenu, that is working well.  I bound the cut, copy, and paste buttons in the radmenu to those of the radrichtextbox with the xaml code:
<telerikNavigation:RadMenuItem x:Name="_cutMenu" DataContext="{Binding ElementName=_rrtbMessage}" Command="{Binding CutCommand}" Header="Cut" />
<telerikNavigation:RadMenuItem x:Name="_copyMenu" DataContext="{Binding ElementName=_rrtbMessage}" Command="{Binding CopyCommand}" Header="Copy" />
<telerikNavigation:RadMenuItem x:Name="_pasteMenu" DataContext="{Binding ElementName=_rrtbMessage}" Command="{Binding PasteCommand}" Header="Paste" />

And that works well.  I tried to do the same thing with a context menu, and non of the buttons seem to work.  They simply respond as if they had no command.  The code I've written for that is:
                   
<telerikDocuments:RadRichTextBox x:Name="_rrtbMessage" HorizontalAlignment="Stretch" Margin="10,35,10,10" VerticalAlignment="Stretch">
<telerikDocuments:RadRichTextBox.Resources>
         <dHTML:HtmlDataProvider x:Key="HtmlDataProvider" RichTextBox="{ Binding ElementName=_rrtbMessage}" Html="{Binding MessageText, Mode=TwoWay}" SetupDocument="SetupMessage" />
</telerikDocuments:RadRichTextBox.Resources>
<telerikNavigation:RadContextMenu.ContextMenu>
<telerikNavigation:RadContextMenu x:Name="_menuRtbFormat">
                        <telerikNavigation:RadMenuItem x:Name="_cutContextMenu" DataContext="{Binding ElementName=_rrtfMessage}" Command="{Binding CutCommand}" Header="Cut" />
                        <telerikNavigation:RadMenuItem x:Name="_copyContextMenu" DataContext="{Binding ElementName=_rrtfMessage}" Command="{Binding CopyCommand}" Header="Copy" />
                        <telerikNavigation:RadMenuItem x:Name="_pasteContextMenu" DataContext="{Binding ElementName=_rrtbMessage}" Command="{Binding PasteCommand}" Header="Paste"
</telerikNavigation:RadContextMenu>
</telerikNavigation:RadContextMenu.ContextMenu>
</telerikDocuments:RadRichTextBox>

Is there something I need to do differently because the context menu is nested inside of the RadRichTextbox I am trying to bind to?

2 Answers, 1 is accepted

Sort by
0
Accepted
Iva Toteva
Telerik team
answered on 20 Oct 2010, 05:36 PM
Hello Michael,

I am attaching a project that shows two ways you can use to make the context menu work - in XAML and in code-behind.
Basically, what you need to change in your code is not bind the DataContext property of the RadMenuItem, but the DataContext property of RadRichTextBox as follows:
<telerikDocuments:RadRichTextBox x:Name="_rrtbMessage" HorizontalAlignment="Stretch"  Margin="10,35,10,10" DataContext="{Binding ElementName=_rrtbMessage, Path=Commands}">
If you have any other questions, do not hesitate to contact us again.

All the best,
Iva
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Michael
Top achievements
Rank 1
answered on 20 Oct 2010, 06:02 PM
Perfect, worked like a charm.
Thanks,
Mike
Tags
RichTextBox
Asked by
Michael
Top achievements
Rank 1
Answers by
Iva Toteva
Telerik team
Michael
Top achievements
Rank 1
Share this question
or