Forum Xamarin.Forms

Custom Renderer Nullable DatePicker with EventToCommandBehaviour on Unfocused not working

ledragonledragon Member ✭✭✭


I've used the following post to implement a nullable DatePicker:

and the following code to create the NullableDatePicker and bind to a command:

var datePicker = new NullableDatePicker()
    BindingContext = rfi,
    FontSize = 14,
    HorizontalOptions = LayoutOptions.FillAndExpand,
    TextColor = Color.White,
    BackgroundColor = Color.FromHex("#4c5a63")

datePicker.SetBinding(NullableDatePicker.NullableDateProperty, new Binding("Response", BindingMode.TwoWay, new StringToDateConverter(), "dd/MM/yyyy"));

datePicker.Behaviors.Add(new EventToCommandBehavior()
    EventName = "Unfocused",
    Command = _editRfisViewModel.EntryUnfocusedCommand,
    CommandParameter = rfi

This implementation doesn't seem to bind the behaviour though as the ViewModel command isn't fired on Unfocus. Can anyone offer some assistance to help how to ensure the Unfocused command fires appropriately?

I've tried;


in the custom renderer Dialog Done and Clear event handlers to no avail.

void CreateDatePickerDialog(int year, int month, int day)
    NullableDatePicker view = Element;

        _dialog = new DatePickerDialog(Context, (o, e) =>
            view.Date = e.Date;
                ((IElementController)view).SetValueFromRenderer(VisualElement.IsFocusedProperty, false);

                _dialog = null;
        }, year, month, day);

        _dialog.SetButton("Done", (sender, e) =>
                this.Element.Format = this.Element._originalFormat;

        _dialog.SetButton2("Clear", (sender, e) =>
                Control.Text = this.Element.Format;

Any help much appreciated.


Sign In or Register to comment.