Skip to content

Commit

Permalink
fix: Fix SelectorExtensions not updating NumberOfPages on Selector lo…
Browse files Browse the repository at this point in the history
…ad (#565)

* fix: Fix SelectorExtensions not updating NumberOfPages on Selector load

* chore: Fix build
  • Loading branch information
Youssef1313 committed May 25, 2023
1 parent 6d54745 commit cccd79f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/Uno.Toolkit.RuntimeTests/Tests/SelectorExtensionsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Uno.UI.RuntimeTests;
using Uno.Toolkit.RuntimeTests.Helpers;
using System.Threading.Tasks;
using Uno.Toolkit.UI;
using Microsoft.UI.Xaml.Controls;

#if !IS_WINUI
using Windows.UI.Xaml.Controls;
#endif

namespace Uno.Toolkit.RuntimeTests.Tests
{
[TestClass]
[RunsOnUIThread]
public class SelectorExtensionsTests
{
[TestMethod]
public async Task TestAddingItemsBeforeLoadedAndAfterSetPipsPager()
{
var grid = new Grid();
var flipView = new FlipView();
var pipsPager = new PipsPager();
grid.Children.Add(flipView);
grid.Children.Add(pipsPager);
SelectorExtensions.SetPipsPager(flipView, pipsPager);
flipView.Items.Add("Test1");
flipView.Items.Add("Test2");
flipView.Items.Add("Test3");
await UnitTestUIContentHelperEx.SetContentAndWait(grid);
Assert.AreEqual(3, pipsPager.NumberOfPages);
}
}
}
1 change: 1 addition & 0 deletions src/Uno.Toolkit.UI/Behaviors/SelectorExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ private static void OnSelectorLoaded(object sender, RoutedEventArgs? e)
events.SetValue(selector, SelectorAttachedPropertyKey, eventHandler);

selector.Items.VectorChanged += eventHandler;
pipsPager.NumberOfPages = selector.Items.Count;

void OnItemsVectorChanged(IObservableVector<object> sender, IVectorChangedEventArgs @event) =>
pipsPager.NumberOfPages = selector.Items.Count;
Expand Down

0 comments on commit cccd79f

Please sign in to comment.