Binding mvvmcross MvxBind on actionSend(imeOption操作)
我有这样的编辑文本:Binding mvvmcross MvxBind on actionSend(imeOption操作),binding,xamarin.android,mvvmcross,mvxbind,Binding,Xamarin.android,Mvvmcross,Mvxbind,我有这样的编辑文本: <EditText local:MvxBind="Text MyProperty; Click MyCommand" android:inputType="textShortMessage" android:imeOptions="actionSend" /> 我希望该命令由键盘上的“回车/动作”键触发。我应该在绑定中使用什么动词?我目前在控件中的任何触摸上使用的“更改”动词都会触发!(如果您想实现“
<EditText
local:MvxBind="Text MyProperty; Click MyCommand"
android:inputType="textShortMessage"
android:imeOptions="actionSend" />
我希望该命令由键盘上的“回车/动作”键触发。我应该在绑定中使用什么动词?我目前在控件中的任何触摸上使用的“更改”动词都会触发!(如果您想实现“自定义绑定”,那么有三种方法:
中的答案显示了一个真正的自定义绑定
中的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
}
使用中间对象进行绑定将使用以下类:
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
}
这可以在OnCreate
中使用流畅的绑定处理,如:
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();
}
private DoneActionListener\u listener;
公共重写OnCreate(Bundle b)
{
base.OnCreate(b);
SetContentView(Resource.Layout.MyLayoutId);
_listener=newdoneactionlistener(findviewbyd(Resource.Id.MyEditId));
var set=this.CreateBindingSet();
set.Bind(_listener).For(v=>v.DoneAction).To(vm=>vm.TheDoneCommand);
set.Apply();
}
如果要实现“自定义绑定”,则有三种方法:
中的答案显示了一个真正的自定义绑定
中的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
}
使用中间对象进行绑定将使用以下类:
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
}
这可以在OnCreate
中使用流畅的绑定处理,如:
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();
}
private DoneActionListener\u listener;
公共重写OnCreate(Bundle b)
{
base.OnCreate(b);
SetContentView(Resource.Layout.MyLayoutId);
_listener=newdoneactionlistener(findviewbyd(Resource.Id.MyEditId));
var set=this.CreateBindingSet();
set.Bind(_listener).For(v=>v.DoneAction).To(vm=>vm.TheDoneCommand);
set.Apply();
}
类似于Well,但不是真的。他希望在焦点丢失时触发一些东西。我不:)我需要自定义转换器吗?什么都没有?如果需要,我会写的。但如果我想将其添加为贡献,它应该放在哪个mvvmcross文件/文件夹中?类似于Well,但不是真的。他想在失去注意力的时候发射一些东西。我不:)我需要自定义转换器吗?什么都没有?如果需要,我会写的。但如果我想将其添加为贡献,它应该放在哪个mvvmcross文件/文件夹中?是否可以使用MvxAndroidTargetBinding?对于类型为ICommand?的TargetType,我尝试了解决方案1,但自定义绑定中没有ICommand绑定支持(除了调试之外,我还检查了源代码)。因此,解决方案1不是一种实现这一点的方法。或者我错过了什么。也许它不是MvxAndroidTargetBinding。在这个类中,您永远无法直接访问“ViewModelTarget”属性。并且无法触发ICommand目标。是否可以改用MvxAndroidTargetBinding?对于类型为ICommand?的TargetType,我尝试了解决方案1,但自定义绑定中没有ICommand绑定支持(除了调试之外,我还检查了源代码)。因此,解决方案1不是一种实现这一点的方法。或者我错过了什么。也许它不是MvxAndroidTargetBinding。在这个类中,您永远无法直接访问“ViewModelTarget”属性。并且不能触发ICommand目标。