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

[UWP] Fixed EmptyView crash using RefreshView #11913

Merged
merged 2 commits into from
Sep 4, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Xamarin.Forms.Controls.Issues.Issue11794"
Title="Issue 11794">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Label
Padding="12"
BackgroundColor="Black"
TextColor="White"
Text="If the CollectionView renders without exceptions with data and being empty, the test has passed."/>
<RefreshView
Grid.Row="1">
<CollectionView
x:Name="EmptyCollectionView">
<CollectionView.ItemsLayout>
<GridItemsLayout
Orientation="Vertical"
Span="3" />
</CollectionView.ItemsLayout>
<CollectionView.ItemTemplate>
<DataTemplate>
<Frame>
<Label
Text="{Binding .}" />
</Frame>
</DataTemplate>
</CollectionView.ItemTemplate>
<CollectionView.EmptyView>
<StackLayout>
<Label
Text="Welcome to crashtown" />
</StackLayout>
</CollectionView.EmptyView>
</CollectionView>
</RefreshView>
<RefreshView
Grid.Row="2">
<CollectionView
x:Name="NonEmptyCollectionView"
ItemsSource="{Binding Items}">
<CollectionView.ItemsLayout>
<GridItemsLayout
Orientation="Vertical"
Span="3" />
</CollectionView.ItemsLayout>
<CollectionView.ItemTemplate>
<DataTemplate>
<Frame>
<Label
Text="{Binding .}" />
</Frame>
</DataTemplate>
</CollectionView.ItemTemplate>
<CollectionView.EmptyView>
<StackLayout>
<Label
Text="Welcome to crashtown" />
</StackLayout>
</CollectionView.EmptyView>
</CollectionView>
</RefreshView>
</Grid>
</ContentPage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System;
using System.Collections.ObjectModel;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;

namespace Xamarin.Forms.Controls.Issues
{
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Github, 11794, "[Bug] RefreshView with CollectionView child cannot contain GridItemsLayout with Span greater than 1 in combination with EmptyView on UWP",
PlatformAffected.UWP)]
public partial class Issue11794 : ContentPage
{
public Issue11794()
{
#if APP
InitializeComponent();
BindingContext = new Issue11794ViewModel();
#endif
}
}

[Preserve(AllMembers = true)]
public class Issue11794ViewModel : BindableObject
{
ObservableCollection<string> _items;

public Issue11794ViewModel()
{
LoadItems();
}

public ObservableCollection<string> Items
{
get { return _items; }
set
{
_items = value;
OnPropertyChanged();
}
}

void LoadItems()
{
Items = new ObservableCollection<string>
{
"Item 1",
"Item 2",
"Item 3"
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Issue10744.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue10909.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue11794.xaml.cs">
<DependentUpon>Issue11794.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Issue8613.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue9137.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue8691.cs" />
Expand Down Expand Up @@ -2225,4 +2228,10 @@
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue11794.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion Xamarin.Forms.Platform.UAP/CollectionView/FormsGridView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ protected override void OnApplyTemplate()

_emptyViewContentControl = GetTemplateChild("EmptyViewContentControl") as ContentControl;

if (_emptyView != null)
if (_emptyView != null && _emptyViewContentControl != null)
{
_emptyViewContentControl.Content = _emptyView;
}
Expand Down