Horizontal CollecitonView UWP scrolling with mouse fixed (#11629)

Co-authored-by: Emil Alipiev <emil_alipiev@hotmail.com>
fixes #9631
This commit is contained in:
Emil Alipiev 2020-08-04 23:44:45 +02:00 коммит произвёл GitHub
Родитель 628185beb5
Коммит b34bb79e8c
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 113 добавлений и 5 удалений

Просмотреть файл

@ -0,0 +1,106 @@
using System.Collections.ObjectModel;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
using System;
using Xamarin.Forms.Xaml;
using System.Collections.Generic;
#if UITEST
using Xamarin.UITest;
using Xamarin.UITest.Queries;
using NUnit.Framework;
using Xamarin.Forms.Core.UITests;
using System.Linq;
#endif
namespace Xamarin.Forms.Controls.Issues
{
#if UITEST
[Category(UITestCategories.CollectionView)]
#endif
#if APP
[XamlCompilation(XamlCompilationOptions.Compile)]
#endif
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Github, 9631, "[CollectionView] How to scroll in Horizontal CollectionView",
PlatformAffected.UWP)]
public partial class Issue9631 : TestContentPage
{
protected override void Init()
{
CollectionView collectionView = new CollectionView { ItemsLayout = LinearItemsLayout.Horizontal, };
collectionView.ItemTemplate = new DataTemplate(() =>
{
var stacklayout = new StackLayout
{
Orientation = StackOrientation.Vertical,
Spacing = 5,
Padding = 10,
BackgroundColor = Color.Beige
};
Image image = new Image { Aspect = Aspect.AspectFill, HeightRequest = 60, WidthRequest = 60 };
image.SetBinding(Image.SourceProperty, "Source");
Label nameLabel = new Label { FontAttributes = FontAttributes.Bold };
nameLabel.SetBinding(Label.TextProperty, "Text");
nameLabel.SetBinding(Label.AutomationIdProperty, "AutomationId");
stacklayout.Children.Add(image);
stacklayout.Children.Add(nameLabel);
return stacklayout;
});
Content = collectionView;
collectionView.SetBinding(ItemsView.ItemsSourceProperty, "Items");
BindingContext = new ViewModel9631();
}
[Preserve(AllMembers = true)]
public class ViewModel9631
{
public ObservableCollection<Model9631> Items { get; set; }
public ViewModel9631()
{
var collection = new ObservableCollection<Model9631>();
var pageSize = 50;
for (var i = 0; i < pageSize; i++)
{
collection.Add(new Model9631
{
Text = "Image" + i,
Source = "coffee.png",
AutomationId = "Image" + i
});
}
Items = collection;
}
}
[Preserve(AllMembers = true)]
public class Model9631
{
public string Text { get; set; }
public string Source { get; set; }
public string AutomationId { get; set; }
public Model9631()
{
}
}
}
}

Просмотреть файл

@ -71,6 +71,7 @@
<SubType>Code</SubType>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Issue9580.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue9631.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue9682.xaml.cs">
<DependentUpon>Issue9682.xaml</DependentUpon>
<SubType>Code</SubType>
@ -1414,7 +1415,6 @@
<Compile Include="$(MSBuildThisFileDirectory)Issue10477.xaml.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue10875.xaml.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue10708.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue9711.xaml.cs">
<DependentUpon>Issue9711.xaml</DependentUpon>
<SubType>Code</SubType>

Просмотреть файл

@ -1,6 +1,8 @@
using System;
using System.ComponentModel;
using Windows.UI.Xaml.Controls;
using UWPApp = Windows.UI.Xaml.Application;
using WListView = Windows.UI.Xaml.Controls.ListView;
using WScrollMode = Windows.UI.Xaml.Controls.ScrollMode;
@ -61,7 +63,7 @@ namespace Xamarin.Forms.Platform.UWP
return CreateHorizontalListView(listItemsLayout);
}
throw new NotImplementedException("The layout is not implemented");
throw new NotImplementedException("The layout is not implemented");
}
protected virtual void UpdateHeader()
@ -220,10 +222,10 @@ namespace Xamarin.Forms.Platform.UWP
ItemsPanel = (ItemsPanelTemplate)UWPApp.Current.Resources["HorizontalListItemsPanel"],
ItemContainerStyle = GetHorizontalItemContainerStyle(listItemsLayout)
};
ScrollViewer.SetVerticalScrollBarVisibility(horizontalListView, Windows.UI.Xaml.Controls.ScrollBarVisibility.Hidden);
ScrollViewer.SetVerticalScrollMode(horizontalListView, WScrollMode.Disabled);
ScrollViewer.SetHorizontalScrollMode(horizontalListView, WScrollMode.Auto);
ScrollViewer.SetHorizontalScrollBarVisibility(horizontalListView,
Windows.UI.Xaml.Controls.ScrollBarVisibility.Auto);
ScrollViewer.SetHorizontalScrollBarVisibility(horizontalListView, Windows.UI.Xaml.Controls.ScrollBarVisibility.Auto);
return horizontalListView;
}