Skip to content

Commit a93d609

Browse files
SubhikshaSf4851PureWeen
authored andcommitted
[Windows] Fix for CarouselView IsSwipeEnabled=False Prevents Visual Navigation (#29286)
* [Windows] Fix for Carousel View doesn't scroll programmatically * Test case sample
1 parent d10a130 commit a93d609

File tree

3 files changed

+85
-2
lines changed

3 files changed

+85
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,11 @@ void UpdateIsSwipeEnabled()
235235
{
236236
case ItemsLayoutOrientation.Horizontal:
237237
ScrollViewer.SetHorizontalScrollMode(ListViewBase, ItemsView.IsSwipeEnabled ? WScrollMode.Auto : WScrollMode.Disabled);
238-
ScrollViewer.SetHorizontalScrollBarVisibility(ListViewBase, ItemsView.IsSwipeEnabled ? WScrollBarVisibility.Auto : WScrollBarVisibility.Disabled);
238+
ScrollViewer.SetHorizontalScrollBarVisibility(ListViewBase, ItemsView.IsSwipeEnabled ? WScrollBarVisibility.Auto : WScrollBarVisibility.Hidden);
239239
break;
240240
case ItemsLayoutOrientation.Vertical:
241241
ScrollViewer.SetVerticalScrollMode(ListViewBase, ItemsView.IsSwipeEnabled ? WScrollMode.Auto : WScrollMode.Disabled);
242-
ScrollViewer.SetVerticalScrollBarVisibility(ListViewBase, ItemsView.IsSwipeEnabled ? WScrollBarVisibility.Auto : WScrollBarVisibility.Disabled);
242+
ScrollViewer.SetVerticalScrollBarVisibility(ListViewBase, ItemsView.IsSwipeEnabled ? WScrollBarVisibility.Auto : WScrollBarVisibility.Hidden);
243243
break;
244244
}
245245
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using Maui.Controls.Sample.Issues;
2+
3+
namespace Controls.TestCases.HostApp.Issues;
4+
5+
[Issue(IssueTracker.Github, 29216, "Carousel view scrolling on button click", PlatformAffected.UWP)]
6+
public class Issue29216 : TestContentPage
7+
{
8+
protected override void Init()
9+
{
10+
var items = new List<string> { "Page1", "Page2" };
11+
12+
CarouselView carouselView = new CarouselView
13+
{
14+
ItemsSource = items,
15+
IsSwipeEnabled = false,
16+
Loop = false,
17+
ItemTemplate = new DataTemplate(() =>
18+
{
19+
var label = new Label
20+
{
21+
HorizontalOptions = LayoutOptions.Center,
22+
VerticalOptions = LayoutOptions.Center,
23+
FontSize = 24,
24+
TextColor = Colors.Black,
25+
};
26+
27+
label.SetBinding(Label.TextProperty, ".");
28+
label.SetBinding(Label.AutomationIdProperty, ".");
29+
30+
return new StackLayout
31+
{
32+
Children = { label }
33+
};
34+
}),
35+
HeightRequest = 300
36+
};
37+
38+
var button1 = new Button
39+
{
40+
Text = "Go to Page 2",
41+
AutomationId = "button"
42+
};
43+
44+
button1.Clicked += (s, e) => carouselView.Position = 1;
45+
46+
Content = new StackLayout
47+
{
48+
Padding = 20,
49+
Children =
50+
{
51+
new StackLayout
52+
{
53+
Orientation = StackOrientation.Horizontal,
54+
Children = { button1 }
55+
},
56+
carouselView
57+
}
58+
};
59+
}
60+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using NUnit.Framework;
2+
using UITest.Appium;
3+
using UITest.Core;
4+
5+
namespace Microsoft.Maui.TestCases.Tests.Issues;
6+
7+
public class Issue29216 : _IssuesUITest
8+
{
9+
public Issue29216(TestDevice device) : base(device)
10+
{
11+
}
12+
13+
public override string Issue => "Carousel view scrolling on button click";
14+
15+
[Test]
16+
[Category(UITestCategories.CarouselView)]
17+
public void Issue29216CarouselViewScrollingIssue()
18+
{
19+
App.WaitForElement("button");
20+
App.Tap("button");
21+
App.WaitForElement("Page2");
22+
}
23+
}

0 commit comments

Comments
 (0)