summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoradrianknight89 <adrianknight89@outlook.com>2016-12-28 23:15:45 (GMT)
committerE.Z. Hart <hartez@users.noreply.github.com>2016-12-28 23:15:45 (GMT)
commit4ea528643e8c23c8cde47d312665c6fe08701d6d (patch)
tree819c77248ef61653c2309b5aa39bb30b3c4b8312
parentc1d83aacba24f35f056be5b7e792096650d9b7be (diff)
downloadxamarin-forms-4ea528643e8c23c8cde47d312665c6fe08701d6d.zip
xamarin-forms-4ea528643e8c23c8cde47d312665c6fe08701d6d.tar.gz
xamarin-forms-4ea528643e8c23c8cde47d312665c6fe08701d6d.tar.bz2
fix nre when changing content in datepickerselected (#494)
-rw-r--r--Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla38723.cs58
-rw-r--r--Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems1
-rw-r--r--Xamarin.Forms.Platform.iOS/Renderers/PickerRenderer.cs2
3 files changed, 60 insertions, 1 deletions
diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla38723.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla38723.cs
new file mode 100644
index 0000000..2defade
--- /dev/null
+++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla38723.cs
@@ -0,0 +1,58 @@
+´╗┐using System;
+using Xamarin.Forms.CustomAttributes;
+using Xamarin.Forms.Internals;
+
+#if UITEST
+using Xamarin.UITest;
+using NUnit.Framework;
+#endif
+
+namespace Xamarin.Forms.Controls
+{
+ [Preserve(AllMembers = true)]
+ [Issue(IssueTracker.Bugzilla, 38723, "Update Content in Picker's SelectedIndexChanged event causes NullReferenceException", PlatformAffected.iOS)]
+ public class Bugzilla38723 : TestContentPage // or TestMasterDetailPage, etc ...
+ {
+ Picker _datePicker;
+ Label _dateLabel;
+
+ protected override void Init()
+ {
+ _datePicker = new Picker
+ {
+ //HorizontalOptions = LayoutOptions.FillAndExpand,
+ VerticalOptions = LayoutOptions.Center,
+ Title = "Pick a Date",
+ };
+ _datePicker.SelectedIndexChanged += DatePickerSelected;
+
+ for (var i = 0; i < 7; i++)
+ {
+ _datePicker.Items.Add(DateTime.Now.AddDays(i).ToString("dd, MMM, yyyy(dddd)"));
+ }
+
+ var stackLayout = new StackLayout
+ {
+ Padding = new Thickness(10, 10)
+ };
+
+ _dateLabel = new Label
+ {
+ HorizontalOptions = LayoutOptions.StartAndExpand,
+ VerticalOptions = LayoutOptions.Center,
+ Text = "Placeholder"
+ };
+
+ stackLayout.Children.Add(_datePicker);
+ stackLayout.Children.Add(_dateLabel);
+ // Update current page's UI would cause NullReferenceException
+ Content = stackLayout;
+ }
+
+ void DatePickerSelected(object sender, EventArgs args)
+ {
+ _dateLabel.Text = args.ToString();
+ Content = _dateLabel;
+ }
+ }
+} \ No newline at end of file
diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems
index 895bcc9..53ae50a 100644
--- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems
+++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems
@@ -82,6 +82,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla37863.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla37601.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla38105.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)Bugzilla38723.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla38827.xaml.cs">
<DependentUpon>Bugzilla38827.xaml</DependentUpon>
<SubType>Code</SubType>
diff --git a/Xamarin.Forms.Platform.iOS/Renderers/PickerRenderer.cs b/Xamarin.Forms.Platform.iOS/Renderers/PickerRenderer.cs
index 5a7fa22..169ac3e 100644
--- a/Xamarin.Forms.Platform.iOS/Renderers/PickerRenderer.cs
+++ b/Xamarin.Forms.Platform.iOS/Renderers/PickerRenderer.cs
@@ -108,9 +108,9 @@ namespace Xamarin.Forms.Platform.iOS
if (Element != null)
{
var oldText = Control.Text;
- ElementController.SetValueFromRenderer(Picker.SelectedIndexProperty, s.SelectedIndex);
Control.Text = s.SelectedItem;
UpdatePickerNativeSize(oldText);
+ ElementController.SetValueFromRenderer(Picker.SelectedIndexProperty, s.SelectedIndex);
}
}