Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 91519

If I paste something in an Entry, it doesn't fire Trigger

$
0
0

Hi guys,
I have an Entry with some Triggers. One of them is checking is an email is valid. The problem is that a user pastes an email, the Entry doesn't fire the Triggers.

How can I update an Entry in this case?

I tried to prevent Cut, Paste or Copy but it doesn't work.

iOS

[assembly: ExportRenderer(typeof(Entry), typeof(EntryCustomRenderer))]
namespace MyProject.iOS.Renderers
{
    /// <summary> 
    /// Entry extra renderer. 
    /// </summary> 
    public class EntryCustomRenderer : EntryRenderer
    {
        [...]

        public override bool CanPerform(ObjCRuntime.Selector action, Foundation.NSObject withSender)
        {
            if (action.Name == "paste:" || action.Name == "copy:" || action.Name == "cut:")
                return false;

            return base.CanPerform(action, withSender);
        }
    }
}

Android

Callback

namespace MyProject.Droid.Renderers
{
    public class Callback : Java.Lang.Object, ActionMode.ICallback
    {
        public bool OnActionItemClicked(ActionMode mode, IMenuItem item)
        {
            return false;
        }

        public bool OnCreateActionMode(ActionMode mode, IMenu menu)
        {
            return false;
        }

        public void OnDestroyActionMode(ActionMode mode)
        {
        }

        public bool OnPrepareActionMode(ActionMode mode, IMenu menu)
        {
            return false;
        }
    }
}

EntryRender

public class EntryCustomRenderer : EntryRenderer
{
    protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
    {
        base.OnElementChanged(e);
        [...]

        // prevent copy/paste
        Control.CustomSelectionActionModeCallback = new Callback();
    }
}

Thanks in advance


Viewing all articles
Browse latest Browse all 91519

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>