The binding syntax doesn't provide UpdateSourceTrigger
The only ways to change the triggering mechanism are:
- to provide a custom binding
- or to provide a custom control
I'd go for custom binding - something like:
public class MvxEditTextFocusChangeTextSpecialTargetBinding
: MvxAndroidTargetBinding
{
protected EditText EditText
{
get { return (EditText)Target; }
}
private bool _subscribed;
public MvxEditTextFocusChangeTextSpecialTargetBinding(EditText view)
: base(view)
{
}
protected override void SetValueImpl(object target, object value)
{
var editText = EditText;
if (editText == null)
return;
value = value ?? string.Empty;
editText.Text = value.ToString();
}
public override MvxBindingMode DefaultMode
{
get { return MvxBindingMode.TwoWay; }
}
public override void SubscribeToEvents()
{
var editText = EditText;
if (editText == null)
return;
editText.FocusChange += HandleFocusChange;
_subscribed = true;
}
private void HandleFocusChange(object sender, View.FocusChangeEventArgs e)
{
var editText = EditText;
if (editText == null)
return;
if (!e.HasFocus)
FireValueChanged(editText.Text);
}
public override Type TargetType
{
get { return typeof(string); }
}
protected override void Dispose(bool isDisposing)
{
if (isDisposing)
{
var editText = EditText;
if (editText != null && _subscribed)
{
editText.FocusChange -= HandleFocusChange;
_subscribed = false;
}
}
base.Dispose(isDisposing);
}
}
registered using:
registry.RegisterCustomBindingFactory<EditText>("FocusText",
textView => new MvxEditTextFocusChangeTextSpecialTargetBinding(textView));
then used as:
local:MvxBind="FocusText VMProperty"
For more on custom bindings, see the N=28 tutorial - http://slodge.blogspot.co.uk/2013/06/n28-custom-bindings-n1-days-of-mvvmcross.html
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…