Adding more ContextMenuItems to RadMaskedContextMenu

5 posts, 1 answers
  1. Inger Marie
    Inger Marie avatar
    60 posts
    Member since:
    Nov 2010

    Posted 21 Nov 2011 Link to this post

    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!
  2. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 24 Nov 2011 Link to this post

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

  3. UI for WPF is Visual Studio 2017 Ready
  4. Inger Marie
    Inger Marie avatar
    60 posts
    Member since:
    Nov 2010

    Posted 05 Dec 2011 Link to this post

    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?
  5. Answer
    Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 08 Dec 2011 Link to this post

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

  6. Inger Marie
    Inger Marie avatar
    60 posts
    Member since:
    Nov 2010

    Posted 12 Sep 2012 Link to this post

    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.
Back to Top
UI for WPF is Visual Studio 2017 Ready