The goal is to display dialog for user to select date on tap on EditText
.
I'm truing to implement binding that will show dialog on click. The code is the following:
public class EditDateBinding : BindingWrapper<EditText, DateTime>
{
public EditDateBinding(EditText androidControl) : base(androidControl)
{
}
public override void SubscribeToEvents()
{
Target.Click += InputClick;
}
private void InputClick(object sender, EventArgs args)
{
DateTime parsedDate = DateTime.Now;
DateTime.TryParse(Target.Text, CultureInfo.CurrentCulture, DateTimeStyles.None, out parsedDate);
var dialog = new DatePickerDialogFragment(Target.Context, parsedDate, OnDateSet);
dialog.Show(
// Can't get fragment manager here
, "date");
}
private void OnDateSet(object sender, DatePickerDialog.DateSetEventArgs e)
{
SetValueToView(Target, e.Date);
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
if (isDisposing)
{
if (Target != null)
{
Target.Click -= InputClick;
}
}
}
protected override void SetValueToView(EditText androidControl, DateTime value)
{
androidControl.Text = value.ToShortDateString();
}
}
But I cant find a way to get FragmentManager
instance in order to call Show
method of instantiated dialog. Can this be implemented in any way?