mvvmcross MvxBind on actionSend(imeOption动作)

Sof*_*ion 1 binding xamarin.android mvvmcross mvxbind

我有一个像这样的editText:

    <EditText
        local:MvxBind="Text MyProperty; Click MyCommand"
        android:inputType="textShortMessage"
        android:imeOptions="actionSend" />
Run Code Online (Sandbox Code Playgroud)

我希望命令由键盘上的"输入/操作"键触发.我应该在绑定中使用什么动词?"更改"动词我当前在控件中的任何触摸上使用触发器!(

Stu*_*art 5

如果要实现"自定义绑定",则有3种方法可以执行此操作:

  1. 实现并注册真正的自定义绑定
  2. 实现一个自定义控件,该控件公开要绑定的自定义属性
  3. 使用公开自定义属性的中间对象

/sf/answers/1345496981/中的答案显示了真正的自定义绑定.


http://mvvmcross.blogspot.com中的N = 18中讨论了从标准视图继承的自定义控件- 这里的示例可能是:

public class DoneEditText : EditText, TextView.IOnEditorActionListener
{
    public DoneEditText(Context context) : base(context)
    {
        Init();
    }

    public DoneEditText(Context context, IAttributeSet attrs) : base(context, attrs)
    {
        Init();
    }

    public DoneEditText(Context context, IAttributeSet attrs, int defStyle) : base(context, attrs, defStyle)
    {
        Init();
    }

    private void Init()
    {
          this.SetOnEditorActionListener(this);
    }

    public ICommand DoneAction { get;set; ]

    #region Implementation of IOnEditorActionListener

    public bool OnEditorAction(TextView v, ImeAction actionId, KeyEvent e)
    {
        if (actionId == ImeAction.Done)
        {
            if (DoneAction != null)
                    DoneAction.Execute(v.Text);
            return true;
        }

        return false;
    }

    #endregion
}    
Run Code Online (Sandbox Code Playgroud)

使用中间对象进行绑定将使用如下类:

public class DoneActionListener : Java.Lang.Object, TextView.IOnEditorActionListener
{
    public ICommand DoneAction { get; set; }

    public DoneActionListener(TextView v)
    {
          v.SetOnEditorActionListener(this);
   }

    #region Implementation of IOnEditorActionListener

    public bool OnEditorAction(TextView v, ImeAction actionId, KeyEvent e)
    {
        if (actionId == ImeAction.Done)
        {
            if (DoneAction != null)
                    DoneAction.Execute(v.Text);
            return true;
        }

        return false;
    }

    #endregion
}
Run Code Online (Sandbox Code Playgroud)

这可以OnCreate使用Fluent Binding 来处理,如:

private DoneActionListener _listener;

public override OnCreate(Bundle b)
{
    base.OnCreate(b);
    SetContentView(Resource.Layout.MyLayoutId);

    _listener = new DoneActionListener(FindViewById<EditText>(Resource.Id.MyEditId));

    var set = this.CreateBindingSet<MyView, MyViewModel>();
    set.Bind(_listener).For(v => v.DoneAction).To(vm => vm.TheDoneCommand);
    set.Apply();
}
Run Code Online (Sandbox Code Playgroud)