Skip to content

Commit

Permalink
[Windows] - Picker on windows shows "Microsoft.Maui.Controls.Picker" …
Browse files Browse the repository at this point in the history
…if ItemsSource has an empty string (#24276)

* fix-8845-Picker on windows shows "Microsoft.Maui.Controls.Picker" if ItemsSource has an empty string

* Added image for test case

* Updated Script file

* Modified test case

* modified test case

* Modified test case

* Modified test case

* Modified test case

* Modified code changes
  • Loading branch information
NirmalKumarYuvaraj authored Oct 16, 2024
1 parent 4c66e4a commit f86bf47
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 2 deletions.
13 changes: 13 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issues8845.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
Title="Issue 8845"
x:Class="Maui.Controls.Sample.Issues.Issue8845">

<VerticalStackLayout>
<Picker AutomationId="MauiPicker1" x:Name="picker1" ItemDisplayBinding="{Binding DisplayName}"/>
<Picker AutomationId="MauiPicker2" x:Name="picker2" ItemDisplayBinding="{Binding DisplayName}"/>
<Button AutomationId="UpdateButton" Text="Update" Clicked="Button_Clicked"/>
</VerticalStackLayout>

</ContentPage>
29 changes: 29 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issues8845.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.Xaml;

namespace Maui.Controls.Sample.Issues
{
[XamlCompilation(XamlCompilationOptions.Compile)]
[Issue(IssueTracker.Github, 8845, "Picker on windows shows \"Microsoft.Maui.Controls.Picker\" if ItemsSource has an empty string", PlatformAffected.UWP)]
public partial class Issue8845 : ContentPage
{
public Issue8845()
{
InitializeComponent();
var items = new List<object>
{
new { DisplayName = (string)null!},
new { DisplayName = "Not null"},
};
picker1.ItemsSource = items;
picker2.ItemsSource = items;
}

private void Button_Clicked(object sender, EventArgs e)
{
picker1.SelectedIndex = 0;
picker2.SelectedIndex = 1;
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;


namespace Microsoft.Maui.TestCases.Tests.Issues
{
public class Issue8845 : _IssuesUITest
{
public Issue8845(TestDevice testDevice) : base(testDevice)
{
}

public override string Issue => "Picker on windows shows \"Microsoft.Maui.Controls.Picker\" if ItemsSource has an empty string";

[Test]
[Category(UITestCategories.Picker)]
public void PickerShouldDisplayValueFromItemDisplayBinding()
{
App.WaitForElement("UpdateButton");
App.Tap("UpdateButton");

var picker1Text = App.WaitForElement("MauiPicker1").GetText();
var picker2Text = App.WaitForElement("MauiPicker2").GetText();

Assert.That(picker1Text, Is.Empty);
Assert.That(picker2Text, Is.EqualTo("Not null"));
}
}
}
3 changes: 1 addition & 2 deletions src/Core/src/Platform/Windows/PickerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ public static class PickerExtensions
{
public static void UpdateTitle(this ComboBox nativeComboBox, IPicker picker)
{
nativeComboBox.Header = null;
nativeComboBox.Header = string.IsNullOrEmpty(picker.Title) ? null : picker;

nativeComboBox.HeaderTemplate = string.IsNullOrEmpty(picker.Title) ? null :
(UI.Xaml.DataTemplate)UI.Xaml.Application.Current.Resources["ComboBoxHeader"];

nativeComboBox.DataContext = picker;
}

public static void UpdateBackground(this ComboBox nativeComboBox, IPicker picker)
Expand Down

0 comments on commit f86bf47

Please sign in to comment.