-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Fix Picker ItemDisplayBinding doesn't support MVVM properly #29922
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
devanathan-vaithiyanathan
wants to merge
12
commits into
dotnet:main
Choose a base branch
from
devanathan-vaithiyanathan:fix-25634
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
b62420f
fix added
devanathan-vaithiyanathan 1918236
method name changed
devanathan-vaithiyanathan b981f70
fix added
devanathan-vaithiyanathan 5ac909b
condition updated
devanathan-vaithiyanathan 4667737
condition updated
devanathan-vaithiyanathan 971faf0
test case added
devanathan-vaithiyanathan 5c0cf0d
test case updated
devanathan-vaithiyanathan 2c1806e
modified the test case
devanathan-vaithiyanathan dffad1d
addressed the review comments
devanathan-vaithiyanathan 31c0539
Android snapshot added
devanathan-vaithiyanathan 7713707
iOS snapshot added
devanathan-vaithiyanathan 6e94f72
Windows and mac snap added
devanathan-vaithiyanathan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+17 KB
...stCases.Android.Tests/snapshots/android/VerifyPickerItemDisplayBindingValue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
using System.Collections.ObjectModel; | ||
using System.ComponentModel; | ||
using System.Runtime.CompilerServices; | ||
using Microsoft.Maui.Controls; | ||
|
||
namespace Maui.Controls.Sample.Issues; | ||
|
||
[Issue(IssueTracker.Github, 25634, "Picker ItemDisplayBinding doesn't support MVVM properly", PlatformAffected.All)] | ||
public class Issue25634 : ContentPage | ||
{ | ||
public ObservableCollection<Issue25634_Model> People { get; private set; } = new() | ||
{ | ||
new Issue25634_Model { FirstName = "John", LastName = "Doe" }, | ||
new Issue25634_Model { FirstName = "Jane", LastName = "Smith" }, | ||
new Issue25634_Model { FirstName = "Sam", LastName = "Johnson" } | ||
}; | ||
|
||
Picker picker; | ||
|
||
public Issue25634() | ||
{ | ||
BindingContext = this; | ||
|
||
picker = new Picker(); | ||
picker.SetBinding(Picker.ItemsSourceProperty, nameof(People)); | ||
picker.ItemDisplayBinding = new Binding("LastName"); | ||
|
||
var button = new Button | ||
{ | ||
Text = "Click", | ||
AutomationId = "PickerButton" | ||
}; | ||
button.Clicked += Button_Clicked; | ||
|
||
var stackLayout = new VerticalStackLayout | ||
{ | ||
Padding = new Thickness(30, 0), | ||
Spacing = 25 | ||
}; | ||
stackLayout.Children.Add(picker); | ||
stackLayout.Children.Add(button); | ||
|
||
Content = stackLayout; | ||
|
||
picker.SelectedItem = People[0]; | ||
} | ||
|
||
void Button_Clicked(object sender, EventArgs e) | ||
{ | ||
if (People.Count > 0) | ||
{ | ||
People[0].LastName = "Alice"; | ||
} | ||
} | ||
} | ||
|
||
public class Issue25634_Model : INotifyPropertyChanged | ||
{ | ||
private string firstName = "FirstName"; | ||
private string lastName = "LastName"; | ||
|
||
public string FirstName | ||
{ | ||
get => firstName; | ||
set | ||
{ | ||
if (firstName != value) | ||
{ | ||
firstName = value; | ||
OnPropertyChanged(); | ||
} | ||
} | ||
} | ||
|
||
public string LastName | ||
{ | ||
get => lastName; | ||
set | ||
{ | ||
if (lastName != value) | ||
{ | ||
lastName = value; | ||
OnPropertyChanged(); | ||
} | ||
} | ||
} | ||
|
||
public event PropertyChangedEventHandler PropertyChanged; | ||
|
||
protected void OnPropertyChanged([CallerMemberName] string name = "") | ||
{ | ||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name)); | ||
} | ||
} |
Binary file added
BIN
+6.33 KB
...tests/TestCases.Mac.Tests/snapshots/mac/VerifyPickerItemDisplayBindingValue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions
22
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue25634.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using NUnit.Framework; | ||
using UITest.Appium; | ||
using UITest.Core; | ||
|
||
namespace Microsoft.Maui.TestCases.Tests.Issues; | ||
public class Issue25634 : _IssuesUITest | ||
{ | ||
public Issue25634(TestDevice testDevice) : base(testDevice) | ||
{ | ||
} | ||
|
||
public override string Issue => "Picker ItemDisplayBinding doesn't support MVVM properly"; | ||
|
||
[Test] | ||
[Category(UITestCategories.Picker)] | ||
public void VerifyPickerItemDisplayBindingValue() | ||
{ | ||
App.WaitForElement("PickerButton"); | ||
App.Tap("PickerButton"); | ||
VerifyScreenshot(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
} |
Binary file added
BIN
+3.83 KB
...TestCases.WinUI.Tests/snapshots/windows/VerifyPickerItemDisplayBindingValue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+18.3 KB
...tests/TestCases.iOS.Tests/snapshots/ios/VerifyPickerItemDisplayBindingValue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic is duplicated, can extract it to a method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inside the methods, check items.Count == 0 before iterating to avoid unnecessary loops