Skip to content

Commit c60db11

Browse files
authored
Fix for [Windows] HorizontalScrollBarVisibility="Never" not working in CarouselView on Windows platform (#29343)
* Update ItemsViewHandler.Windows.cs * Update ItemsViewHandler.Windows.cs * Commit for ScrollBarVisibility * Testcase included * Update Issue15253.cs * Tes * testcases enabled * Update Issue15253.cs * Image updated * method change
1 parent cb4594e commit c60db11

File tree

12 files changed

+122
-9
lines changed

12 files changed

+122
-9
lines changed

src/Controls/src/Core/Handlers/Items/CarouselViewHandler.Windows.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,14 @@ protected override void OnScrollViewerFound(ScrollViewer scrollViewer)
9898
_scrollViewer.ViewChanged += OnScrollViewChanged;
9999
_scrollViewer.SizeChanged += OnScrollViewSizeChanged;
100100

101-
UpdateScrollBarVisibilityForLoop();
101+
if (Element.Loop)
102+
{
103+
UpdateScrollBarVisibilityForLoop();
104+
}
105+
else
106+
{
107+
UpdateScrollBarVisibility();
108+
}
102109
}
103110

104111
protected override ICollectionView GetCollectionView(CollectionViewSource collectionViewSource)

src/Controls/src/Core/Handlers/Items/ItemsViewHandler.Windows.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,8 +351,7 @@ protected virtual void UpdateItemsLayout()
351351

352352
UpdateItemTemplate();
353353
UpdateItemsSource();
354-
UpdateVerticalScrollBarVisibility();
355-
UpdateHorizontalScrollBarVisibility();
354+
UpdateScrollBarVisibility();
356355
UpdateEmptyView();
357356
}
358357

@@ -376,6 +375,12 @@ void ListViewLoaded(object sender, RoutedEventArgs e)
376375
listView.Loaded += ListViewLoaded;
377376
}
378377

378+
internal void UpdateScrollBarVisibility()
379+
{
380+
UpdateVerticalScrollBarVisibility();
381+
UpdateHorizontalScrollBarVisibility();
382+
}
383+
379384
void UpdateVerticalScrollBarVisibility()
380385
{
381386
if (Element.VerticalScrollBarVisibility != ScrollBarVisibility.Default)
22.2 KB
Loading
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
using System.Collections.ObjectModel;
2+
3+
namespace Maui.Controls.Sample.Issues;
4+
5+
[Issue(IssueTracker.Github, 15253, "[Windows]HorizontalScrollBarVisibility doesnot works", PlatformAffected.UWP)]
6+
7+
public class Issue15253 : ContentPage
8+
{
9+
ObservableCollection<Model15253> Items;
10+
public Issue15253()
11+
{
12+
Items = new ObservableCollection<Model15253>();
13+
Items.Add(new Model15253 { Name = "one", AutomationId = "15253One" });
14+
Items.Add(new Model15253 { Name = "two", AutomationId = "15253Two" });
15+
Items.Add(new Model15253 { Name = "three", AutomationId = "15253Three" });
16+
var carouselView = new CarouselView
17+
{
18+
WidthRequest = 200,
19+
HeightRequest = 200,
20+
AutomationId = "15253CarouselView",
21+
Loop = false,
22+
VerticalScrollBarVisibility = ScrollBarVisibility.Never,
23+
HorizontalScrollBarVisibility = ScrollBarVisibility.Never,
24+
BackgroundColor = Colors.LightBlue,
25+
ItemsSource = Items,
26+
ItemTemplate = new DataTemplate(() =>
27+
{
28+
var label = new Label
29+
{
30+
FontSize = 32,
31+
TextColor = Colors.Black,
32+
HorizontalTextAlignment = TextAlignment.Center,
33+
BackgroundColor = Colors.LightBlue
34+
35+
};
36+
label.SetBinding(Label.TextProperty, "Name");
37+
label.SetBinding(Label.AutomationIdProperty, "AutomationId");
38+
39+
var stack = new StackLayout
40+
{
41+
Orientation = StackOrientation.Vertical,
42+
VerticalOptions = LayoutOptions.Center,
43+
HorizontalOptions = LayoutOptions.Center,
44+
WidthRequest = 200,
45+
Children = { label }
46+
};
47+
return new ContentView { Content = stack };
48+
})
49+
};
50+
51+
52+
var toggleButton = new Button
53+
{
54+
Text = "Toggle Scrollbar",
55+
AutomationId = "15253Button"
56+
};
57+
58+
toggleButton.Clicked += (s, e) =>
59+
{
60+
carouselView.HorizontalScrollBarVisibility = carouselView.HorizontalScrollBarVisibility == ScrollBarVisibility.Never
61+
? ScrollBarVisibility.Always
62+
: ScrollBarVisibility.Never;
63+
};
64+
65+
var outerStack = new StackLayout
66+
{
67+
Orientation = StackOrientation.Vertical,
68+
VerticalOptions = LayoutOptions.Center,
69+
HorizontalOptions = LayoutOptions.Center,
70+
Spacing = 8,
71+
Padding = 8,
72+
Children = { toggleButton, carouselView }
73+
};
74+
75+
Content = outerStack;
76+
}
77+
78+
}
79+
public class Model15253
80+
{
81+
public string Name { get; set; }
82+
public string AutomationId { get; set; }
83+
}

src/Controls/tests/TestCases.HostApp/Issues/Issue28098.xaml.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ public partial class Issue28098 : ContentPage
88
public Issue28098()
99
{
1010
InitializeComponent();
11-
#if ANDROID
1211
carouselView.HorizontalScrollBarVisibility = ScrollBarVisibility.Never;
13-
#endif
1412
}
1513

1614
protected override void OnAppearing()
-355 Bytes
Loading
9.08 KB
Loading
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using NUnit.Framework;
2+
using UITest.Core;
3+
using UITest.Appium;
4+
5+
namespace Microsoft.Maui.TestCases.Tests.Issues
6+
{
7+
internal class Issue15253 : _IssuesUITest
8+
{
9+
public override string Issue => "[Windows]HorizontalScrollBarVisibility doesnot works";
10+
public Issue15253(TestDevice device) : base(device)
11+
{
12+
}
13+
14+
[Test]
15+
[Category(UITestCategories.CarouselView)]
16+
public void HorizontalScrollBarShouldHideOnNever()
17+
{
18+
// Is a Windows issue; see https://github.com/dotnet/maui/issues/15253
19+
App.WaitForElement("15253CarouselView");
20+
App.Tap("one");
21+
VerifyScreenshot();
22+
}
23+
}
24+
}

src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue28098.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ public void BlankScreenOnNavigationBack()
1818
App.Tap("Button");
1919
App.WaitForElement("BackButton");
2020
App.Tap("BackButton");
21-
#if WINDOWS
22-
VerifyScreenshot(cropBottom: 250);
23-
#else
2421
VerifyScreenshot();
25-
#endif
2622
}
2723
}
1.55 KB
Loading

0 commit comments

Comments
 (0)