Forum Xamarin.iOS

How to disable a paste menu in Secure Text field.

simeon_Msimeon_M USMember ✭✭

I'd like to know how to disable Paste in Secure Text field.

I created custom secure text field and custom secure text field cell as below.

But, I can not handle the context menu and paste from menu at all.

Do you have any hint to disable this?



  • simeon_Msimeon_M USMember ✭✭

    I'd like to disable this menu.

  • YuriKuznetsovYuriKuznetsov USMember ✭✭✭
    edited June 2018

    You have a few solutions, you need to create your own SecureTextField and in Xcode set name of your class.

    public class SecureTextField : NSSecureTextField {
        public SecureTextField(IntPtr handle) : base(handle) {
            //option 1 remove all menu items 
            foreach (var menuItem in Menu.ItemArray()) 
        //option 2 this method always call before menu will show 
        //in this case you always need to check - cut, copy, delete action of menu and enabling or disabling them
        public bool ValidateMenuItem(NSMenuItem sender) {
            var actionName = sender.Action.Name;
            switch (actionName) {
                //paste menu will be always disabled
                case "paste:": 
                    return false;
                case "selectAll:":
                    return true;
                    return false;
  • simeon_Msimeon_M USMember ✭✭

    Thank you.

    Unfortunately, both your suggestions doesn't work.
    Option 1: Menu is null at constructor.
    Option 2: ValidateMenuItem() is not called at all.

    I implemented as below.

  • simeon_Msimeon_M USMember ✭✭

    Oh. Do you mean we have no way to control context menu on SecureTextField ?
    TextView has that way...

  • YuriKuznetsovYuriKuznetsov USMember ✭✭✭

    In this topic says every NSTextField and NSSecureTextField has NSTextView with context menu which you showed in screen, and NSTextView control context menu, I do not know how get NSTextView.
    I found only property CurrentEditor which return NSControl may be that it is.

  • simeon_Msimeon_M USMember ✭✭

    I confirmed CurrentEditor. It's NSText object.
    When I remove CurrentEditor.Menu Items, Text field menu is disabled. But SecureTextField is still there.

    Unfortunately, I can't disable context menu on SecureTextField yet.

Sign In or Register to comment.