-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
[Windows] Fix wrong Layout from hidden CollectionView #17659
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
src/Controls/samples/Controls.Sample.UITests/Issues/Issue17400.xaml
This file contains 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,45 @@ | ||
<?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" | ||
x:Class="Maui.Controls.Sample.Issues.Issue17400" | ||
xmlns:ns="clr-namespace:Maui.Controls.Sample.Issues" | ||
Title="Issue 17400"> | ||
<Grid | ||
Padding="30,0" | ||
VerticalOptions="Center" | ||
RowDefinitions="*, Auto"> | ||
<CollectionView | ||
x:Name="ItemsView" | ||
ItemsSource="{Binding Items}" | ||
IsVisible="{Binding AreItemsVisible}"> | ||
<CollectionView.ItemTemplate> | ||
<DataTemplate> | ||
<Grid | ||
HeightRequest="60" | ||
RowDefinitions=" 30,29,1"> | ||
<Label | ||
AutomationId="WaitForStubControl" | ||
Grid.Row="0" | ||
Text="{Binding Label}" | ||
FontSize="20" | ||
FontAttributes="Bold"/> | ||
<Label | ||
Grid.Row="1" | ||
Text="{Binding Description}" | ||
FontSize="16"/> | ||
<BoxView | ||
Grid.Row="2" | ||
HeightRequest="1" | ||
Color="Red" /> | ||
</Grid> | ||
</DataTemplate> | ||
</CollectionView.ItemTemplate> | ||
</CollectionView> | ||
<Button | ||
Grid.Row="1" | ||
AutomationId="UpdateBtn" | ||
Text="Change Visibility" | ||
Command="{Binding UpdateCommand}" | ||
HorizontalOptions="Center" /> | ||
</Grid> | ||
</ContentPage> |
78 changes: 78 additions & 0 deletions
78
src/Controls/samples/Controls.Sample.UITests/Issues/Issue17400.xaml.cs
This file contains 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,78 @@ | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.Linq; | ||
using System.Windows.Input; | ||
using Microsoft.Maui.Controls; | ||
using Microsoft.Maui.Controls.Xaml; | ||
|
||
namespace Maui.Controls.Sample.Issues | ||
{ | ||
internal class Issue17400Item : BindableObject | ||
{ | ||
public string Label { get; set; } | ||
|
||
public string Description { get; set; } | ||
} | ||
|
||
internal class Issue17400ViewModel : BindableObject | ||
{ | ||
ObservableCollection<Issue17400Item> _items; | ||
bool _areItemsVisible; | ||
|
||
public Issue17400ViewModel() | ||
{ | ||
List<Issue17400Item> items = new List<Issue17400Item>(); | ||
|
||
foreach (var item in Enumerable.Range(0, 20)) | ||
{ | ||
items.Add(new Issue17400Item | ||
{ | ||
Label = "Label " + item, | ||
Description = "Description " + item, | ||
}); | ||
} | ||
|
||
Items = new ObservableCollection<Issue17400Item>(items); | ||
AreItemsVisible = false; | ||
} | ||
|
||
public ObservableCollection<Issue17400Item> Items | ||
{ | ||
get { return _items; } | ||
set | ||
{ | ||
_items = value; | ||
OnPropertyChanged(); | ||
} | ||
} | ||
|
||
public bool AreItemsVisible | ||
{ | ||
get { return _areItemsVisible; } | ||
set | ||
{ | ||
_areItemsVisible = value; | ||
OnPropertyChanged(); | ||
} | ||
} | ||
|
||
public ICommand UpdateCommand => new Command(Update); | ||
|
||
void Update() | ||
{ | ||
AreItemsVisible = !AreItemsVisible; | ||
} | ||
} | ||
|
||
[XamlCompilation(XamlCompilationOptions.Compile)] | ||
[Issue(IssueTracker.Github, 17400, "CollectionView wrong Layout", PlatformAffected.UWP)] | ||
public partial class Issue17400 : ContentPage | ||
{ | ||
public Issue17400() | ||
{ | ||
InitializeComponent(); | ||
|
||
BindingContext = new Issue17400ViewModel(); | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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,27 @@ | ||
using Microsoft.Maui.Appium; | ||
using NUnit.Framework; | ||
|
||
namespace Microsoft.Maui.AppiumTests.Issues | ||
{ | ||
public class Issue17400 : _IssuesUITest | ||
{ | ||
public Issue17400(TestDevice device) | ||
: base(device) | ||
{ } | ||
|
||
public override string Issue => "CollectionView wrong Layout"; | ||
|
||
[Test] | ||
public void Issue17400Test() | ||
{ | ||
UITestContext.IgnoreIfPlatforms(new TestDevice[] { TestDevice.iOS, TestDevice.Android, TestDevice.Mac }, | ||
"Is a Windows issue; see https://github.com/dotnet/maui/issues/17400"); | ||
|
||
App.WaitForElement("UpdateBtn"); | ||
App.Tap("UpdateBtn"); | ||
|
||
App.WaitForElement("WaitForStubControl"); | ||
VerifyScreenshot(); | ||
jsuarezruiz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
} |
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.
With an invisible CollectionView, the
_wrapGrid
will be null (VisualTreeHelper.GetChildrenCount will return 0) and will not apply the correct sizes.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.
not sure to what extent this matters, but it looks like you can subscribe to ChoosingItemContainer and call FindItemsWrapGrid from there.
It just feels a bit weird to set the size information of the WrappedGrid inside the ArrangeOverride call.
Thoughts on just calling it from there?
And then even for good measure
I also wonder if we should null at the grid and unsubscribe when the orientation is changed.
The Orientation applies a different template so the wrapgrid is going to change.
But maybe this GridView is recreated when the orientation gets changed?