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

Adding more ContextMenuItems to RadMaskedContextMenu

4 Answers 87 Views
ContextMenu
This is a migrated thread and some comments may be shown as answers.
Inger Marie
Top achievements
Rank 1
Inger Marie asked on 21 Nov 2011, 01:38 PM
I have need for adding more context menues to a RadMasketContextMenu - but I want to keep the three original (copy, cut, paste).

 <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

Sort by
0
Petar Mladenov
Telerik team
answered on 24 Nov 2011, 02:48 PM
Hi Inger Marie,

 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.

Regards,
Petar Mladenov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Inger Marie
Top achievements
Rank 1
answered on 05 Dec 2011, 03:32 PM
Thanks for your reply.. It didn't work for me, though...

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?
0
Accepted
Petar Mladenov
Telerik team
answered on 08 Dec 2011, 12:50 PM
Hi Inger Marie,

 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 >>

0
Inger Marie
Top achievements
Rank 1
answered on 12 Sep 2012, 12:26 PM
Ok, it took me a while but I eventually got there

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.
Tags
ContextMenu
Asked by
Inger Marie
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
Inger Marie
Top achievements
Rank 1
Share this question
or