I will like to change the default binding trigger from PropertyChanged to LostFocus on a Droid EditText view:
<EditText
android:layout_width="fill_parent"
android:layout_gravity="center"
android:textSize="16dp"
android:minWidth="168dp"
local:MvxBind="Text SelectedCode, UpdateSourceTrigger=LostFocus" />
But I cannot find the correct syntax from the Wiki
I know this is possible within the framework but cannot find the reference.
Ideas?
TIA.
The binding syntax doesn't provide UpdateSourceTrigger
The only ways to change the triggering mechanism are:
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With