UIKit.UIResponder.CanPerform Method
Determines if this UIResponder can perform the specified action. Typically used to probe for editing commands.

Syntax

[Foundation.Export("canPerformAction:withSender:")]
public virtual bool CanPerform (ObjCRuntime.Selector action, Foundation.NSObject withSender)

Parameters

action
The selector that represents the action that is being probed. For editing operations, these selectors are "copy:", "cut:", "delete:", "paste:", "select:", "selectAll:", "toggleBoldface:", "toggleItalics:", "toggleUnderline:".
withSender

The object invoking this method.

This parameter can be null.

Returns

True if the specified action can be performed with the specified sender.

Remarks

This method should return true if the action specified by the selector can be performed by the object.

c# Example

//
// Selectable label: a label that shows the "Copy" menu when the user
// long presses
//
public class SelectableLabel : UILabel {

    public SelectableLabel (RectangleF rect) : base (rect)
    {
    	UserInteractionEnabled = true;
    	var gesture = new UILongPressGestureRecognizer (LongPress);
    	AddGestureRecognizer (gesture);
    }
    
    void LongPress (UILongPressGestureRecognizer r)
    {
    	var location = r.LocationInView (r.View);
    	var menu = UIMenuController.SharedMenuController;
    
    	r.View.BecomeFirstResponder ();
    
    	menu.SetTargetRect (r.View.Frame, r.View);
    	menu.SetMenuVisible (true, true);
    }
    			
    
    public override bool CanBecomeFirstResponder { 
    	get { return true; } 
    }

    Selector copyAction = new Selector ("copy");

    public override bool CanPerform (Selector action, NSObject withSender)
    {
    	if (action == copyAction);
    		return true;
    	return false;
    }
    
    public override void Copy (NSObject sender)
    {
    	UIPasteboard.General.String = this.Text;
    }
}
	    

Requirements

Namespace: UIKit
Assembly: Xamarin.iOS (in Xamarin.iOS.dll)
Assembly Versions: 0.0.0.0