-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Issue5749.xaml.cs
103 lines (90 loc) · 3.13 KB
/
Issue5749.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
using System;
using System.Collections.Generic;
using Xamarin.Forms;
using System.Threading.Tasks;
using System.Collections.ObjectModel;
using System.ComponentModel;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
using System.Collections;
using System.Linq;
#if UITEST
using Xamarin.UITest;
using NUnit.Framework;
#endif
namespace Xamarin.Forms.Controls.Issues
{
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Github, 5749, "Disable horizontal scroll in the custom listview in android")]
public partial class Issue5749 : TestContentPage
{
#if UITEST
[Test]
public void DisableScrollingOnCustomHorizontalListView()
{
RunningApp.WaitForElement("Button");
RunningApp.WaitForElement(q => q.Marked("True"), timeout: TimeSpan.FromSeconds(2));
RunningApp.Screenshot("Custom HorizontalListView Scrolling Enabled Default");
RunningApp.Tap(q => q.Marked("Toggle ScrollView.IsEnabled"));
RunningApp.WaitForElement(q => q.Marked("False"), timeout: TimeSpan.FromSeconds(2));
RunningApp.Screenshot("Custom HorizontalListView Scrolling Disabled");
}
#endif
public Issue5749()
{
#if APP
InitializeComponent();
listViewHorizontal.ItemsSource = new string[] { "item1... ", "item2... ", "item3... ", "item4... ", "item5... ", "item6... ", "item7... ", "item8... ", "item9... ", "item10... " };
#endif
}
protected override void Init()
{
}
void ToggleScrollViewIsEnabled(object sender, EventArgs args)
{
#if APP
listViewHorizontal.IsEnabled = !listViewHorizontal.IsEnabled;
#endif
}
}
[Preserve(AllMembers = true)]
public class CustomHorizontalListview : ScrollView
{
public static readonly BindableProperty ItemsSourceProperty =
BindableProperty.Create("ItemsSource", typeof(IEnumerable), typeof(CustomHorizontalListview), default(IEnumerable));
public IEnumerable ItemsSource
{
get { return (IEnumerable)GetValue(ItemsSourceProperty); }
set { SetValue(ItemsSourceProperty, value); }
}
public static readonly BindableProperty ItemTemplateProperty =
BindableProperty.Create("ItemTemplate", typeof(DataTemplate), typeof(CustomHorizontalListview), default(DataTemplate));
public DataTemplate ItemTemplate
{
get { return (DataTemplate)GetValue(ItemTemplateProperty); }
set { SetValue(ItemTemplateProperty, value); }
}
public static readonly BindableProperty SelectedCommandParameterProperty =
BindableProperty.Create("SelectedCommandParameter", typeof(object), typeof(CustomHorizontalListview), null);
public object SelectedCommandParameter
{
get { return GetValue(SelectedCommandParameterProperty); }
set { SetValue(SelectedCommandParameterProperty, value); }
}
public void Render()
{
if (ItemTemplate == null || ItemsSource == null)
return;
var layout = new StackLayout();
layout.Padding = 20;
layout.Orientation = Orientation == ScrollOrientation.Vertical ? StackOrientation.Vertical : StackOrientation.Horizontal;
foreach (var item in ItemsSource)
{
var viewCell = ItemTemplate.CreateContent() as ViewCell;
viewCell.View.BindingContext = item;
layout.Children.Add(viewCell.View);
}
Content = layout;
}
}
}