* Added repro sample * Updated repro sample * Updated EmptyView logic in UWP to propagate the BC
This commit is contained in:
Родитель
830b0bfc06
Коммит
47e55a852e
|
@ -0,0 +1,103 @@
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
|
using Xamarin.Forms.CustomAttributes;
|
||||||
|
using Xamarin.Forms.Internals;
|
||||||
|
|
||||||
|
#if UITEST
|
||||||
|
using NUnit.Framework;
|
||||||
|
using Xamarin.Forms.Core.UITests;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace Xamarin.Forms.Controls.Issues
|
||||||
|
{
|
||||||
|
[Preserve(AllMembers = true)]
|
||||||
|
[Issue(IssueTracker.Github, 9833, "[Bug] [UWP] Propagate CollectionView BindingContext to EmptyView",
|
||||||
|
PlatformAffected.UWP)]
|
||||||
|
#if UITEST
|
||||||
|
[Category(UITestCategories.CollectionView)]
|
||||||
|
#endif
|
||||||
|
public class Issue9833 : TestContentPage
|
||||||
|
{
|
||||||
|
readonly CollectionView _collectionView;
|
||||||
|
readonly Label _emptyLabel;
|
||||||
|
|
||||||
|
public Issue9833()
|
||||||
|
{
|
||||||
|
Title = "Issue 9833";
|
||||||
|
|
||||||
|
BindingContext = new Issue9833ViewModel();
|
||||||
|
|
||||||
|
var layout = new StackLayout
|
||||||
|
{
|
||||||
|
Padding = 0
|
||||||
|
};
|
||||||
|
|
||||||
|
var instructions = new Label
|
||||||
|
{
|
||||||
|
Text = "If the EmptyView BindingContext is not null, the test has passed.",
|
||||||
|
BackgroundColor = Color.Black,
|
||||||
|
TextColor = Color.White
|
||||||
|
};
|
||||||
|
|
||||||
|
_collectionView = new CollectionView();
|
||||||
|
_collectionView.SetBinding(ItemsView.ItemsSourceProperty, "Items");
|
||||||
|
|
||||||
|
var emptyView = new StackLayout
|
||||||
|
{
|
||||||
|
BackgroundColor = Color.LightGray
|
||||||
|
};
|
||||||
|
|
||||||
|
_emptyLabel = new Label
|
||||||
|
{
|
||||||
|
Text = "This is the EmptyView. "
|
||||||
|
};
|
||||||
|
|
||||||
|
emptyView.Children.Add(_emptyLabel);
|
||||||
|
|
||||||
|
_collectionView.EmptyView = emptyView;
|
||||||
|
|
||||||
|
layout.Children.Add(instructions);
|
||||||
|
layout.Children.Add(_collectionView);
|
||||||
|
|
||||||
|
Content = layout;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Init()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnAppearing()
|
||||||
|
{
|
||||||
|
base.OnAppearing();
|
||||||
|
|
||||||
|
var emptyView = (View)_collectionView.EmptyView;
|
||||||
|
_emptyLabel.Text += $"BindingContext = {emptyView.BindingContext}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Preserve(AllMembers = true)]
|
||||||
|
public class Issue9833ViewModel : BindableObject
|
||||||
|
{
|
||||||
|
ObservableCollection<string> _items;
|
||||||
|
|
||||||
|
public Issue9833ViewModel()
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ObservableCollection<string> Items
|
||||||
|
{
|
||||||
|
get { return _items; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_items = value;
|
||||||
|
OnPropertyChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void LoadData()
|
||||||
|
{
|
||||||
|
Items = new ObservableCollection<string>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -196,6 +196,7 @@
|
||||||
<SubType>Code</SubType>
|
<SubType>Code</SubType>
|
||||||
<DependentUpon>Issue9771.xaml</DependentUpon>
|
<DependentUpon>Issue9771.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="$(MSBuildThisFileDirectory)Issue9833.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)RefreshViewTests.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)RefreshViewTests.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Issue7338.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Issue7338.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)ScrollToGroup.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)ScrollToGroup.cs" />
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
using System.Collections.Specialized;
|
using System;
|
||||||
|
using System.Collections.Specialized;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Windows.UI.Xaml;
|
using Windows.UI.Xaml;
|
||||||
using Windows.UI.Xaml.Controls;
|
using Windows.UI.Xaml.Controls;
|
||||||
using Windows.UI.Xaml.Data;
|
using Windows.UI.Xaml.Data;
|
||||||
using Windows.UI.Xaml.Controls.Primitives;
|
|
||||||
using Windows.Foundation;
|
|
||||||
using Xamarin.Forms.Internals;
|
using Xamarin.Forms.Internals;
|
||||||
using UwpScrollBarVisibility = Windows.UI.Xaml.Controls.ScrollBarVisibility;
|
using UwpScrollBarVisibility = Windows.UI.Xaml.Controls.ScrollBarVisibility;
|
||||||
using UWPApp = Windows.UI.Xaml.Application;
|
using UWPApp = Windows.UI.Xaml.Application;
|
||||||
|
@ -21,7 +20,8 @@ namespace Xamarin.Forms.Platform.UWP
|
||||||
UwpScrollBarVisibility? _defaultHorizontalScrollVisibility;
|
UwpScrollBarVisibility? _defaultHorizontalScrollVisibility;
|
||||||
UwpScrollBarVisibility? _defaultVerticalScrollVisibility;
|
UwpScrollBarVisibility? _defaultVerticalScrollVisibility;
|
||||||
FrameworkElement _emptyView;
|
FrameworkElement _emptyView;
|
||||||
View _formsEmptyView;
|
View _formsEmptyView;
|
||||||
|
bool _emptyViewDisplayed;
|
||||||
ScrollViewer _scrollViewer;
|
ScrollViewer _scrollViewer;
|
||||||
internal double _previousHorizontalOffset;
|
internal double _previousHorizontalOffset;
|
||||||
internal double _previousVerticalOffset;
|
internal double _previousVerticalOffset;
|
||||||
|
@ -388,7 +388,7 @@ namespace Xamarin.Forms.Platform.UWP
|
||||||
}
|
}
|
||||||
|
|
||||||
(ListViewBase as IEmptyView)?.SetEmptyView(_emptyView, _formsEmptyView);
|
(ListViewBase as IEmptyView)?.SetEmptyView(_emptyView, _formsEmptyView);
|
||||||
|
|
||||||
UpdateEmptyViewVisibility();
|
UpdateEmptyViewVisibility();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -413,25 +413,46 @@ namespace Xamarin.Forms.Platform.UWP
|
||||||
|
|
||||||
FrameworkElement RealizeEmptyView(View view)
|
FrameworkElement RealizeEmptyView(View view)
|
||||||
{
|
{
|
||||||
_formsEmptyView = view;
|
_formsEmptyView = view ?? throw new ArgumentNullException(nameof(view));
|
||||||
return view.GetOrCreateRenderer().ContainerElement;
|
return view.GetOrCreateRenderer().ContainerElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void UpdateEmptyViewVisibility()
|
protected virtual void UpdateEmptyViewVisibility()
|
||||||
{
|
{
|
||||||
if (_emptyView != null && ListViewBase is IEmptyView emptyView)
|
bool isEmpty = (CollectionViewSource?.View?.Count ?? 0) == 0;
|
||||||
{
|
|
||||||
emptyView.EmptyViewVisibility = (CollectionViewSource?.View?.Count ?? 0) == 0
|
|
||||||
? Visibility.Visible
|
|
||||||
: Visibility.Collapsed;
|
|
||||||
|
|
||||||
if (emptyView.EmptyViewVisibility == Visibility.Visible)
|
if (isEmpty)
|
||||||
|
{
|
||||||
|
if (_formsEmptyView != null)
|
||||||
{
|
{
|
||||||
if (ActualWidth >= 0 && ActualHeight >= 0)
|
if (_emptyViewDisplayed)
|
||||||
{
|
ItemsView.RemoveLogicalChild(_formsEmptyView);
|
||||||
_formsEmptyView?.Layout(new Rectangle(0, 0, ActualWidth, ActualHeight));
|
|
||||||
}
|
if (ItemsView.EmptyViewTemplate == null)
|
||||||
|
ItemsView.AddLogicalChild(_formsEmptyView);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_emptyView != null && ListViewBase is IEmptyView emptyView)
|
||||||
|
{
|
||||||
|
emptyView.EmptyViewVisibility = Visibility.Visible;
|
||||||
|
|
||||||
|
if (ActualWidth >= 0 && ActualHeight >= 0)
|
||||||
|
_formsEmptyView?.Layout(new Rectangle(0, 0, ActualWidth, ActualHeight));
|
||||||
|
}
|
||||||
|
|
||||||
|
_emptyViewDisplayed = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (_emptyViewDisplayed)
|
||||||
|
{
|
||||||
|
if (_emptyView != null && ListViewBase is IEmptyView emptyView)
|
||||||
|
emptyView.EmptyViewVisibility = Visibility.Collapsed;
|
||||||
|
|
||||||
|
ItemsView.RemoveLogicalChild(_formsEmptyView);
|
||||||
|
}
|
||||||
|
|
||||||
|
_emptyViewDisplayed = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче