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

Commit 027afa9

Browse files
[UWP] Fixed a crash loading the EmptyView in UWP (#11913) fixes #11794
Co-authored-by: Samantha Houts <[email protected]>
1 parent ce56e24 commit 027afa9

File tree

4 files changed

+133
-2
lines changed

4 files changed

+133
-2
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ContentPage
3+
xmlns="http://xamarin.com/schemas/2014/forms"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
5+
x:Class="Xamarin.Forms.Controls.Issues.Issue11794"
6+
Title="Issue 11794">
7+
<Grid>
8+
<Grid.RowDefinitions>
9+
<RowDefinition Height="Auto" />
10+
<RowDefinition />
11+
<RowDefinition />
12+
</Grid.RowDefinitions>
13+
<Label
14+
Padding="12"
15+
BackgroundColor="Black"
16+
TextColor="White"
17+
Text="If the CollectionView renders without exceptions with data and being empty, the test has passed."/>
18+
<RefreshView
19+
Grid.Row="1">
20+
<CollectionView
21+
x:Name="EmptyCollectionView">
22+
<CollectionView.ItemsLayout>
23+
<GridItemsLayout
24+
Orientation="Vertical"
25+
Span="3" />
26+
</CollectionView.ItemsLayout>
27+
<CollectionView.ItemTemplate>
28+
<DataTemplate>
29+
<Frame>
30+
<Label
31+
Text="{Binding .}" />
32+
</Frame>
33+
</DataTemplate>
34+
</CollectionView.ItemTemplate>
35+
<CollectionView.EmptyView>
36+
<StackLayout>
37+
<Label
38+
Text="Welcome to crashtown" />
39+
</StackLayout>
40+
</CollectionView.EmptyView>
41+
</CollectionView>
42+
</RefreshView>
43+
<RefreshView
44+
Grid.Row="2">
45+
<CollectionView
46+
x:Name="NonEmptyCollectionView"
47+
ItemsSource="{Binding Items}">
48+
<CollectionView.ItemsLayout>
49+
<GridItemsLayout
50+
Orientation="Vertical"
51+
Span="3" />
52+
</CollectionView.ItemsLayout>
53+
<CollectionView.ItemTemplate>
54+
<DataTemplate>
55+
<Frame>
56+
<Label
57+
Text="{Binding .}" />
58+
</Frame>
59+
</DataTemplate>
60+
</CollectionView.ItemTemplate>
61+
<CollectionView.EmptyView>
62+
<StackLayout>
63+
<Label
64+
Text="Welcome to crashtown" />
65+
</StackLayout>
66+
</CollectionView.EmptyView>
67+
</CollectionView>
68+
</RefreshView>
69+
</Grid>
70+
</ContentPage>
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using System;
2+
using System.Collections.ObjectModel;
3+
using Xamarin.Forms.CustomAttributes;
4+
using Xamarin.Forms.Internals;
5+
6+
namespace Xamarin.Forms.Controls.Issues
7+
{
8+
[Preserve(AllMembers = true)]
9+
[Issue(IssueTracker.Github, 11794, "[Bug] RefreshView with CollectionView child cannot contain GridItemsLayout with Span greater than 1 in combination with EmptyView on UWP",
10+
PlatformAffected.UWP)]
11+
public partial class Issue11794 : ContentPage
12+
{
13+
public Issue11794()
14+
{
15+
#if APP
16+
InitializeComponent();
17+
BindingContext = new Issue11794ViewModel();
18+
#endif
19+
}
20+
}
21+
22+
[Preserve(AllMembers = true)]
23+
public class Issue11794ViewModel : BindableObject
24+
{
25+
ObservableCollection<string> _items;
26+
27+
public Issue11794ViewModel()
28+
{
29+
LoadItems();
30+
}
31+
32+
public ObservableCollection<string> Items
33+
{
34+
get { return _items; }
35+
set
36+
{
37+
_items = value;
38+
OnPropertyChanged();
39+
}
40+
}
41+
42+
void LoadItems()
43+
{
44+
Items = new ObservableCollection<string>
45+
{
46+
"Item 1",
47+
"Item 2",
48+
"Item 3"
49+
};
50+
}
51+
}
52+
}

Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
</Compile>
2727
<Compile Include="$(MSBuildThisFileDirectory)Issue10744.cs" />
2828
<Compile Include="$(MSBuildThisFileDirectory)Issue10909.cs" />
29+
<Compile Include="$(MSBuildThisFileDirectory)Issue11794.xaml.cs">
30+
<DependentUpon>Issue11794.xaml</DependentUpon>
31+
</Compile>
2932
<Compile Include="$(MSBuildThisFileDirectory)Issue8613.cs" />
3033
<Compile Include="$(MSBuildThisFileDirectory)Issue9137.cs" />
3134
<Compile Include="$(MSBuildThisFileDirectory)Issue8691.cs" />
@@ -2269,4 +2272,10 @@
22692272
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
22702273
</EmbeddedResource>
22712274
</ItemGroup>
2272-
</Project>
2275+
<ItemGroup>
2276+
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue11794.xaml">
2277+
<SubType>Designer</SubType>
2278+
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
2279+
</EmbeddedResource>
2280+
</ItemGroup>
2281+
</Project>

Xamarin.Forms.Platform.UAP/CollectionView/FormsGridView.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ protected override void OnApplyTemplate()
124124

125125
_emptyViewContentControl = GetTemplateChild("EmptyViewContentControl") as ContentControl;
126126

127-
if (_emptyView != null)
127+
if (_emptyView != null && _emptyViewContentControl != null)
128128
{
129129
_emptyViewContentControl.Content = _emptyView;
130130
}

0 commit comments

Comments
 (0)