set => SetValue(ItemsSourceProperty, value);
}
+ public static readonly BindableProperty HorizontalScrollBarVisibilityProperty = BindableProperty.Create(
+ nameof(HorizontalScrollBarVisibility),
+ typeof(ScrollBarVisibility),
+ typeof(ItemsView),
+ ScrollBarVisibility.Default);
+
+ public ScrollBarVisibility HorizontalScrollBarVisibility
+ {
+ get => (ScrollBarVisibility)GetValue(HorizontalScrollBarVisibilityProperty);
+ set => SetValue(HorizontalScrollBarVisibilityProperty, value);
+ }
+
+
+ public static readonly BindableProperty VerticalScrollBarVisibilityProperty = BindableProperty.Create(
+ nameof(VerticalScrollBarVisibility),
+ typeof(ScrollBarVisibility),
+ typeof(ItemsView),
+ ScrollBarVisibility.Default);
+
+ public ScrollBarVisibility VerticalScrollBarVisibility
+ {
+ get => (ScrollBarVisibility)GetValue(VerticalScrollBarVisibilityProperty);
+ set => SetValue(VerticalScrollBarVisibilityProperty, value);
+ }
+
public void AddLogicalChild(Element element)
{
_logicalChildren.Add(element);
DataChangeObserver _dataChangeViewObserver;
bool _watchingForEmpty;
+ ScrollBarVisibility _defaultHorizontalScrollVisibility = ScrollBarVisibility.Default;
+ ScrollBarVisibility _defaultVerticalScrollVisibility = ScrollBarVisibility.Default;
+
RecyclerView.ItemDecoration _itemDecoration;
- public ItemsViewRenderer(Context context) : base(context)
+ public ItemsViewRenderer(Context context) : base(new ContextThemeWrapper(context, Resource.Style.collectionViewStyle))
{
CollectionView.VerifyCollectionViewFlagEnabled(nameof(ItemsViewRenderer));
_automationPropertiesProvider = new AutomationPropertiesProvider(this);
_effectControlProvider = new EffectControlProvider(this);
+
+ VerticalScrollBarEnabled = false;
+ HorizontalScrollBarEnabled = false;
}
ScrollHelper ScrollHelper => _scrollHelper ?? (_scrollHelper = new ScrollHelper(this));
{
UpdateAdapter();
}
+ else if(changedProperty.Is(ItemsView.HorizontalScrollBarVisibilityProperty))
+ {
+ UpdateHorizontalScrollBarVisibility();
+ }
+ else if (changedProperty.Is(ItemsView.VerticalScrollBarVisibilityProperty))
+ {
+ UpdateVerticalScrollBarVisibility();
+ }
}
protected virtual void UpdateItemsSource()
UpdateFlowDirection();
UpdateItemSpacing();
+ UpdateHorizontalScrollBarVisibility();
+ UpdateVerticalScrollBarVisibility();
+
// Keep track of the ItemsLayout's property changes
if (_layout != null)
{
ItemsView.ScrollToRequested += ScrollToRequested;
}
+ void UpdateVerticalScrollBarVisibility()
+ {
+ if (_defaultVerticalScrollVisibility == ScrollBarVisibility.Default)
+ _defaultVerticalScrollVisibility = VerticalScrollBarEnabled ? ScrollBarVisibility.Always : ScrollBarVisibility.Never;
+
+ var newVerticalScrollVisibility = ItemsView.VerticalScrollBarVisibility;
+
+ if (newVerticalScrollVisibility == ScrollBarVisibility.Default)
+ newVerticalScrollVisibility = _defaultVerticalScrollVisibility;
+
+ VerticalScrollBarEnabled = newVerticalScrollVisibility == ScrollBarVisibility.Always;
+ }
+
+ void UpdateHorizontalScrollBarVisibility()
+ {
+ if (_defaultHorizontalScrollVisibility == ScrollBarVisibility.Default)
+ _defaultHorizontalScrollVisibility =
+ HorizontalScrollBarEnabled ? ScrollBarVisibility.Always : ScrollBarVisibility.Never;
+
+ var newHorizontalScrollVisiblility = ItemsView.HorizontalScrollBarVisibility;
+
+ if (newHorizontalScrollVisiblility == ScrollBarVisibility.Default)
+ newHorizontalScrollVisiblility = _defaultHorizontalScrollVisibility;
+
+ HorizontalScrollBarEnabled = newHorizontalScrollVisiblility == ScrollBarVisibility.Always;
+ }
+
protected virtual void TearDownOldElement(ItemsView oldElement)
{
if (oldElement == null)
--- /dev/null
+<?xml version="1.0" encoding="utf-8" ?>
+<resources xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto">
+ <style name="collectionViewStyle" android:id="@+id/collectionViewStyle">
+ <item name="android:scrollbars">vertical|horizontal</item>
+ </style>
+</resources>
<Properties>CreateAllAndroidTargets=false;Configuration=$(Configuration);Platform=$(Platform);AndroidTargetFrameworkVersion=v8.1</Properties>
</ProjectToBuild>
</ItemGroup>
+ <ItemGroup>
+ <AndroidResource Include="Resources\values\styles.xml" />
+ </ItemGroup>
<Target Name="BeforeBuild" Condition=" '$(CreateAllAndroidTargets)' == 'true' ">
<!-- create 8.1 binaries-->
<MSBuild Targets="Restore" Projects="@(ProjectToBuild)">
using Windows.UI.Xaml.Data;
using Xamarin.Forms.Internals;
using Xamarin.Forms.Platform.UAP;
+using UwpScrollBarVisibility = Windows.UI.Xaml.Controls.ScrollBarVisibility;
namespace Xamarin.Forms.Platform.UWP
{
CollectionViewSource _collectionViewSource;
protected ListViewBase ListViewBase { get; private set; }
+ UwpScrollBarVisibility? _defaultHorizontalScrollVisibility;
+ UwpScrollBarVisibility? _defaultVerticalScrollVisibility;
+
+ protected ItemsControl ItemsControl { get; private set; }
protected override void OnElementChanged(ElementChangedEventArgs<CollectionView> args)
{
{
UpdateItemTemplate();
}
+ else if(changedProperty.Is(ItemsView.HorizontalScrollBarVisibilityProperty))
+ {
+ UpdateHorizontalScrollBarVisibility();
+ }
+ else if (changedProperty.Is(ItemsView.VerticalScrollBarVisibilityProperty))
+ {
+ UpdateVerticalScrollBarVisibility();
+ }
}
protected virtual ListViewBase SelectLayout(IItemsLayout layoutSpecification)
UpdateItemTemplate();
UpdateItemsSource();
+ UpdateVerticalScrollBarVisibility();
+ UpdateHorizontalScrollBarVisibility();
// Listen for ScrollTo requests
newElement.ScrollToRequested += ScrollToRequested;
//}
}
+ void UpdateVerticalScrollBarVisibility()
+ {
+ if (_defaultVerticalScrollVisibility == null)
+ _defaultVerticalScrollVisibility = ScrollViewer.GetVerticalScrollBarVisibility(Control);
+
+ switch (Element.VerticalScrollBarVisibility)
+ {
+ case (ScrollBarVisibility.Always):
+ ScrollViewer.SetVerticalScrollBarVisibility(Control, UwpScrollBarVisibility.Visible);
+ break;
+ case (ScrollBarVisibility.Never):
+ ScrollViewer.SetVerticalScrollBarVisibility(Control, UwpScrollBarVisibility.Hidden);
+ break;
+ case (ScrollBarVisibility.Default):
+ ScrollViewer.SetVerticalScrollBarVisibility(Control, _defaultVerticalScrollVisibility.Value);
+ break;
+ }
+ }
+
+ void UpdateHorizontalScrollBarVisibility()
+ {
+ if (_defaultHorizontalScrollVisibility == null)
+ _defaultHorizontalScrollVisibility = ScrollViewer.GetHorizontalScrollBarVisibility(Control);
+
+ switch (Element.HorizontalScrollBarVisibility)
+ {
+ case (ScrollBarVisibility.Always):
+ ScrollViewer.SetHorizontalScrollBarVisibility(Control, UwpScrollBarVisibility.Visible);
+ break;
+ case (ScrollBarVisibility.Never):
+ ScrollViewer.SetHorizontalScrollBarVisibility(Control, UwpScrollBarVisibility.Hidden);
+ break;
+ case (ScrollBarVisibility.Default):
+ ScrollViewer.SetHorizontalScrollBarVisibility(Control, _defaultHorizontalScrollVisibility.Value);
+ break;
+ }
+ }
+
protected virtual async Task ScrollTo(ScrollToRequestEventArgs args)
{
if (!(Control is ListViewBase list))
{
ItemsViewLayout _layout;
bool _disposed;
+ bool? _defaultHorizontalScrollVisibility;
+ bool? _defaultVerticalScrollVisibility;
public ItemsViewRenderer()
{
{
UpdateItemSizingStrategy();
}
+ else if (changedProperty.Is(ItemsView.HorizontalScrollBarVisibilityProperty))
+ {
+ UpdateHorizontalScrollBarVisibility();
+ }
+ else if (changedProperty.Is(ItemsView.VerticalScrollBarVisibilityProperty))
+ {
+ UpdateVerticalScrollBarVisibility();
+ }
}
protected virtual ItemsViewLayout SelectLayout(IItemsLayout layoutSpecification)
ItemsViewController.CollectionView.BackgroundColor = UIColor.Clear;
ItemsViewController.UpdateEmptyView();
+ UpdateHorizontalScrollBarVisibility();
+ UpdateVerticalScrollBarVisibility();
+
// Listen for ScrollTo requests
newElement.ScrollToRequested += ScrollToRequested;
}
return ItemsViewController.GetIndexForItem(args.Item);
}
+ void UpdateVerticalScrollBarVisibility()
+ {
+ if (_defaultVerticalScrollVisibility == null)
+ _defaultVerticalScrollVisibility = ItemsViewController.CollectionView.ShowsHorizontalScrollIndicator;
+
+ switch (Element.VerticalScrollBarVisibility)
+ {
+ case (ScrollBarVisibility.Always):
+ ItemsViewController.CollectionView.ShowsVerticalScrollIndicator = true;
+ break;
+ case (ScrollBarVisibility.Never):
+ ItemsViewController.CollectionView.ShowsVerticalScrollIndicator = false;
+ break;
+ case (ScrollBarVisibility.Default):
+ ItemsViewController.CollectionView.ShowsVerticalScrollIndicator = _defaultVerticalScrollVisibility.Value;
+ break;
+ }
+ }
+
+ void UpdateHorizontalScrollBarVisibility()
+ {
+ if (_defaultHorizontalScrollVisibility == null)
+ _defaultHorizontalScrollVisibility = ItemsViewController.CollectionView.ShowsHorizontalScrollIndicator;
+
+ switch (Element.HorizontalScrollBarVisibility)
+ {
+ case (ScrollBarVisibility.Always):
+ ItemsViewController.CollectionView.ShowsHorizontalScrollIndicator = true;
+ break;
+ case (ScrollBarVisibility.Never):
+ ItemsViewController.CollectionView.ShowsHorizontalScrollIndicator = false;
+ break;
+ case (ScrollBarVisibility.Default):
+ ItemsViewController.CollectionView.ShowsHorizontalScrollIndicator = _defaultHorizontalScrollVisibility.Value;
+ break;
+ }
+ }
+
void ScrollToRequested(object sender, ScrollToRequestEventArgs args)
{
var indexPath = DetermineIndex(args);