This repository has been archived by the owner on May 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix UWP issue with invisible CollectionView and layouts (#14593)
Co-authored-by: Gerald Versluis <gerald.versluis@microsoft.com>
- Loading branch information
1 parent
3ea43c5
commit 197145c
Showing
4 changed files
with
88 additions
and
1 deletion.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue9079.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,31 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<controls:TestContentPage | ||
xmlns:controls="clr-namespace:Xamarin.Forms.Controls" | ||
xmlns="http://xamarin.com/schemas/2014/forms" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
x:Class="Xamarin.Forms.Controls.Issues.Issue9079" | ||
Title="Issue 9079"> | ||
<ContentPage.Content> | ||
<StackLayout> | ||
<Button | ||
Text="Show/Hide CollectionView" | ||
Clicked="Button_Clicked" /> | ||
<CollectionView | ||
x:Name="collectionView" | ||
IsVisible="False"> | ||
<CollectionView.ItemsLayout> | ||
<GridItemsLayout | ||
Orientation="Vertical" | ||
Span="3" /> | ||
</CollectionView.ItemsLayout> | ||
<CollectionView.ItemTemplate> | ||
<DataTemplate> | ||
<Label | ||
VerticalTextAlignment="Center" | ||
Text="{Binding}" /> | ||
</DataTemplate> | ||
</CollectionView.ItemTemplate> | ||
</CollectionView> | ||
</StackLayout> | ||
</ContentPage.Content> | ||
</controls:TestContentPage> |
52 changes: 52 additions & 0 deletions
52
Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue9079.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,52 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.Collections.Generic; | ||
using Xamarin.Forms.CustomAttributes; | ||
using Xamarin.Forms.Internals; | ||
|
||
#if UITEST | ||
using Xamarin.UITest; | ||
using NUnit.Framework; | ||
using Xamarin.Forms.Core.UITests; | ||
#endif | ||
|
||
namespace Xamarin.Forms.Controls.Issues | ||
{ | ||
#if UITEST | ||
[Category(UITestCategories.CollectionView)] | ||
#endif | ||
[Preserve(AllMembers = true)] | ||
[Issue(IssueTracker.Github, 9079, | ||
"[Bug] [UWP] CollectionView ItemsLayout not working when initially invisible", | ||
PlatformAffected.UWP)] | ||
public partial class Issue9079 : TestContentPage | ||
{ | ||
public Issue9079() | ||
{ | ||
#if APP | ||
InitializeComponent(); | ||
GenerateItems(); | ||
#endif | ||
} | ||
|
||
protected override void Init() | ||
{ | ||
|
||
} | ||
#if APP | ||
void GenerateItems() | ||
{ | ||
List<string> items = new List<string>(); | ||
for (int i = 0; i < 100; i++) | ||
items.Add($"Hello world {i}!"); | ||
|
||
collectionView.ItemsSource = items; | ||
} | ||
|
||
void Button_Clicked(object sender, EventArgs e) | ||
{ | ||
collectionView.IsVisible = !collectionView.IsVisible; | ||
} | ||
#endif | ||
} | ||
} |
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
197145c
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 doesn't appear to have solved the issue definitively - in roughly 1/3 of app loads for me I still get an empty view.
What it did do was break my appallingly bad workaround (which was to toggle IsVisible at a short interval until the element had received a Width that was not -1). No matter, I made it InvalidateMeasure() instead of IsVisible and now the workaround works again, but the CollectionView issue remains.
It seems to be a race condition - it only happens on running the project, not on loading a page as such, and from what I've gathered the times it fails seem to be when the program takes longer to load (if I set my hacky workaround to count how many times it triggers itself and waits, I can get a rough time when it finally works - normally around 200ms, sometimes as much as 800-1200ms).
Anyway I'm a bit of a Xamarin noob but I thought it may be worth making a comment here.