<Controls:RadMaskedTextBox x:Name="contactPhone" Style="{StaticResource RadMaskedTextBoxStyle}"
TabIndex="12" Value="{Binding Entity.Phonenumber, NotifyOnSourceUpdated=True, Mode=TwoWay}"
MaskType="None">
<telerik:RadContextMenu.ContextMenu>
<telerik:RadContextMenu>
<telerik:RadMenuItem Header="Hello"/>
</telerik:RadContextMenu>
</telerik:RadContextMenu.ContextMenu>
</Controls:RadMaskedTextBox>
This does not work - I do not get the Hello-context menu added. How do I do this?
Thanks!
4 Answers, 1 is accepted
This is kind of tricky since you have to prevent the default Context Menu to appear from the TextBox inside the RadMaskedTextBox / RadMaskedInput Controls. We created a sample project that implements this requirement for the RadMaskedTextInput control. Basically, we use the PreviewMouseRightButtonDown event (which is handled by default) in order to stop the original context menu and build a new one. The second key moment is to use the Commands from the MaskedInputControl(CopyCommand, PasteCommand, etc.) istead of the ApplicationCommand.Copy, ApplicationCommand.Paste because the MaskedControls does not have handlers for the ApplicationCommands.
Please let us know if the suggested approach fits in your scenario.
Petar Mladenov
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
1. I have a radmaskedtextbox, not a RadMaskedTextInput. As I wrote, MaskType="None". RadMasketTextInput does not have MaskType.
2. RadMaskedTextBox does not have CopyCommand.
3. I really need to reuse the existing copy/paste/cut because I want to use localization... which windows provides to those three context menu items in all other input fields. This one should be the same (headers).
Is this possible?
I modified the last sample to use the RadMaskedTextBox. However, please note that the RadMaskedTextInput is actually an improved version of RadMaskedTextBox with MaskType=None as well as RadMaskedNumericInput is an improved version of RadMaskedTetBox with MaskType=Numeric and etc. The new MaskedInput suite of controls provides new features and many databindings issues from he MaskedTextBox are resolved.
Regards,Petar Mladenov
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
What I did was using the suggested solution (using previewmouserightbuttondown), but with the following change:
MenuItem cutitem = new MenuItem { Header = ApplicationCommands.Cut.Text, Command = ApplicationCommands.Cut, CommandTarget = radMaskedTextBox.ChildrenOfType<
TextBox
>().First() };
radMaskedTextBox.ContextMenu.Items.Add(cutitem);
MenuItem copyItem = new MenuItem { Header = ApplicationCommands.Copy.Text, Command = ApplicationCommands.Copy, CommandTarget = radMaskedTextBox.ChildrenOfType<
TextBox
>().First() };
radMaskedTextBox.ContextMenu.Items.Add(copyItem);
MenuItem pasteitem = new MenuItem { Header = ApplicationCommands.Paste.Text, Command = ApplicationCommands.Paste, CommandTarget = radMaskedTextBox.ChildrenOfType<
TextBox
>().First() };
radMaskedTextBox.ContextMenu.Items.Add(pasteitem);
That way I got the copy, paste and cut text in the right language (I hope).
I am still a bit unsastified by the fact that I have to make a new contextmenu. There clearly was one containing the copy, paste and cut before I changed something and what I really wanted was simply to add more menuitems to that contextmenu.
This works, however.