The DatePicker causes the following exception on Android after opening and closing the page and then tapping the DatePicker Cancel button. Tapping the OK button does not throw this error:
Datepicker Cannot access a disposed object. Object name: 'Xamarin.Forms.Platform.Android.PickerEditText'.
Any ideas how to solve this?
ps. I use Xamarin.Forms 3.6.0.220655
Thanks for asking, I created a test project: turns out this issue occurs with Xamarin.Forms version 3.6.0.220655 (our current version), 3.6.0.264807.
It works as expected using XF version 3.4.0.1008975, 3.6.0.293080, 3.6.0.344457
@NielsCup
I tested your demo and the exception occured. It should be caused by initialization of page. Changing the code as follows can avoid the problem.
public partial class MainPage : ContentPage { //DatePickerPage datePickerPage; public MainPage() { InitializeComponent(); //datePickerPage = new DatePickerPage(); } void Handle_Clicked(object sender, System.EventArgs e) { Navigation.PushModalAsync(new DatePickerPage()); } }
Answers
I tried to reproduce your issue, but failed. Did the exception always occur or just exist once?
The exception occurs when 'The object is terminated when no initialization is complete'. You can try adding an
if
conditional statement.I can reproduce it each time. The funny thing is that it only happens when tapping the pickers "Cancel" button. The "Ok" button works fine. I have made a custom renderer so I can debug the events and see what happens: the Control is null and initialised when expected and CreateNativeControl is called when expected.
Post your code.
You say that you open the page, then close the page, then tap on the DatePicker. Which page is the DatePicker on?
Thanks for asking, I created a test project: turns out this issue occurs with Xamarin.Forms version 3.6.0.220655 (our current version), 3.6.0.264807.
It works as expected using XF version 3.4.0.1008975, 3.6.0.293080, 3.6.0.344457
@NielsCup
I tested your demo and the exception occured. It should be caused by initialization of page. Changing the code as follows can avoid the problem.