Bug 38723 - Update Content in Picker's SelectedIndexChanged event causes NullReferenceException
Summary: Update Content in Picker's SelectedIndexChanged event causes NullReferenceExc...
Status: RESOLVED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms (show other bugs)
Version: 2.0.0
Hardware: PC Windows
: Normal major
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-02-12 18:13 UTC by Jun Zhang
Modified: 2017-03-22 19:46 UTC (History)
9 users (show)

Tags: ac
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Jun Zhang 2016-02-12 18:13:47 UTC
var datePicker = new Picker() {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions = LayoutOptions.Center,
                Title = "Pick a Date",
            };
datePicker.SelectedIndexChanged += DatePickerSelected;

void DatePickerSelected(object sender, EventArgs args) {
            dateLabel.Text = "New Date";
            // Updating current page's UI will cause NullReferenceException
            Content = dateLabel;
}

You can't update Page.Content inside Picker's SelectedIndexChanged event.
Comment 1 Jun Zhang 2016-02-12 18:27:57 UTC
I created a sample project for this bug, which is in link below:
https://www.dropbox.com/s/fk0zs8bafscxzap/PickerBugSample.zip?dl=0
Comment 2 adrianknight89 2016-10-31 16:27:37 UTC
See https://github.com/xamarin/Xamarin.Forms/pull/494
Comment 3 Samantha Houts [MSFT] 2016-12-30 18:37:09 UTC
Should be fixed in 2.3.4-pre2. Thanks!
Comment 4 Parmendra Kumar 2017-02-01 17:57:28 UTC
I have checked this issue with Xamarin.Forms 2.3.4.184-pre1 and observed that this issue still exist.

Screencast: https://www.screencast.com/t/tbGnZox1i

OutputLog: https://gist.github.com/Parmendrak/da41384fd9430fbbc1402c9d63070187


Hence reopening this issue.
Comment 5 Rui Marinho 2017-03-22 19:19:49 UTC
https://github.com/xamarin/Xamarin.Forms/pull/834
Comment 6 Rui Marinho 2017-03-22 19:46:03 UTC
Should be fixed on 2.3.4-pre6