Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
Adding null check for picker items (#9478) fixes #2674
Browse files Browse the repository at this point in the history
  • Loading branch information
sahi82 authored Feb 10, 2020
1 parent 6bd199b commit bbb07f6
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System.Collections.Generic;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;

#if UITEST
using Xamarin.Forms.Core.UITests;
using Xamarin.UITest;
using NUnit.Framework;
#endif

namespace Xamarin.Forms.Controls.Issues
{
#if UITEST
[Category(UITestCategories.Picker)]
#endif
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Github, 2674, "Exception occurs when giving null values in picker itemsource collection", PlatformAffected.All)]
public class Issue2674 : TestContentPage
{
protected override void Init()
{
var _picker = new Picker()
{
ItemsSource = new List<string> { "cat", null, "rabbit" },
AutomationId = "picker",
};

Content = new StackLayout()
{
Children =
{
_picker
}
};
}

#if UITEST
[Test]
public void Issue2674Test()
{
RunningApp.Screenshot("I am at Issue2674");
RunningApp.WaitForElement("picker");
}
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)CollectionViewGroupTypeIssue.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue2674.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue3228.xaml.cs">
<DependentUpon>Issue3228.xaml</DependentUpon>
<SubType>Code</SubType>
Expand Down
2 changes: 1 addition & 1 deletion Xamarin.Forms.Core/Picker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public BindingBase ItemDisplayBinding {
string GetDisplayMember(object item)
{
if (ItemDisplayBinding == null)
return item.ToString();
return item == null ? string.Empty : item.ToString();

ItemDisplayBinding.Apply(item, this, s_displayProperty);
ItemDisplayBinding.Unapply();
Expand Down

0 comments on commit bbb07f6

Please sign in to comment.