private void SetupRepeater(IList data, bool phased)
        {
            var repeater = new ItemsRepeater();

            repeater.ItemsSource = data;
            if (phased)
            {
                repeater.ItemTemplate = (ElementFactory)Resources["SharedElementFactoryPhased"];
            }
            else
            {
                repeater.ItemTemplate = (ElementFactory)Resources["SharedElementFactoryBinding"];
            }

            if (data is IList <Recipe> )
            {
                repeater.Layout = (VirtualizingLayout)Resources["SharedFlowLayout"];
            }
            else
            {
                repeater.Layout = (VirtualizingLayout)Resources["SharedStackLayout"];
            }

            repeater.VerticalCacheLength       = 4.0;
            repeater.XYFocusKeyboardNavigation = Windows.UI.Xaml.Input.XYFocusKeyboardNavigationMode.Enabled;
            var tracker      = new ItemsRepeaterScrollHost();
            var scrollViewer = new Windows.UI.Xaml.Controls.ScrollViewer();

            tracker.ScrollViewer   = scrollViewer;
            scrollViewer.Content   = repeater;
            scrollViewer.IsTabStop = false;
            host.Child             = tracker;

            _printChildrenCount = () => VisualTreeHelper.GetChildrenCount(repeater).ToString();
        }
Exemple #2
0
        public void ValidateRepeaterDefaults()
        {
            RunOnUIThread.Execute(() =>
            {
                var repeater = new ItemsRepeater()
                {
                    ItemsSource = Enumerable.Range(0, 10).Select(i => string.Format("Item #{0}", i)),
                };

                Content = new ItemsRepeaterScrollHost()
                {
                    Width        = 400,
                    Height       = 800,
                    ScrollViewer = new ScrollViewer {
                        Content = repeater
                    }
                };

                Content.UpdateLayout();

                for (int i = 0; i < 10; i++)
                {
                    var element = repeater.TryGetElement(i);
                    Verify.IsNotNull(element);
                    Verify.AreEqual(string.Format("Item #{0}", i), ((TextBlock)element).Text);
                    Verify.AreEqual(i, repeater.GetElementIndex(element));
                }

                Verify.IsNull(repeater.TryGetElement(20));
            });
        }
Exemple #3
0
        public void ValidateElementToIndexMapping()
        {
            ItemsRepeater repeater = null;

            RunOnUIThread.Execute(() =>
            {
                var elementFactory               = new RecyclingElementFactory();
                elementFactory.RecyclePool       = new RecyclePool();
                elementFactory.Templates["Item"] = (DataTemplate)XamlReader.Load(
                    @"<DataTemplate xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'> 
						  <TextBlock Text='{Binding}' Height='50' />
					  </DataTemplate>"                    );

                repeater = new ItemsRepeater()
                {
                    ItemsSource  = Enumerable.Range(0, 10).Select(i => string.Format("Item #{0}", i)),
                    ItemTemplate = elementFactory,
                    // Default is StackLayout, so do not have to explicitly set.
                    // Layout = new StackLayout(),
                };

                Content = new ItemsRepeaterScrollHost()
                {
                    Width        = 400,
                    Height       = 800,
                    ScrollViewer = new ScrollViewer {
                        Content = repeater
                    }
                };

                Content.UpdateLayout();

                for (int i = 0; i < 10; i++)
                {
                    var element = repeater.TryGetElement(i);
                    Verify.IsNotNull(element);
                    Verify.AreEqual(string.Format("Item #{0}", i), ((TextBlock)element).Text);
                    Verify.AreEqual(i, repeater.GetElementIndex(element));
                }

                Verify.IsNull(repeater.TryGetElement(20));
            });
        }
        private ItemsRepeater SetupRepeater(object dataSource, VirtualizingLayout layout, string itemContent, out ScrollViewer scrollViewer)
        {
            ItemsRepeater repeater = null;
            ScrollViewer  sv       = null;

            RunOnUIThread.Execute(() =>
            {
                var elementFactory               = new RecyclingElementFactory();
                elementFactory.RecyclePool       = new RecyclePool();
                elementFactory.Templates["Item"] = (DataTemplate)XamlReader.Load(
                    @"<DataTemplate xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'> " + itemContent + @"</DataTemplate>");

                repeater = new ItemsRepeater()
                {
                    ItemsSource           = dataSource,
                    ItemTemplate          = elementFactory,
                    Layout                = layout,
                    HorizontalCacheLength = 0.0,
                    VerticalCacheLength   = 0.0
                };

                sv = new ScrollViewer
                {
                    Content = repeater
                };

                Content = new ItemsRepeaterScrollHost()
                {
                    Width        = 200,
                    Height       = 200,
                    ScrollViewer = sv
                };
            });

            IdleSynchronizer.Wait();
            scrollViewer = sv;
            return(repeater);
        }
Exemple #5
0
        public void VerifyCorrectionsInNonScrollableDirection()
        {
            ItemsRepeater           rootRepeater = null;
            ScrollViewer            scrollViewer = null;
            ItemsRepeaterScrollHost scrollhost   = null;
            ManualResetEvent        viewChanged  = new ManualResetEvent(false);

            RunOnUIThread.Execute(() =>
            {
                scrollhost = (ItemsRepeaterScrollHost)XamlReader.Load(
                    @"<controls:ItemsRepeaterScrollHost Width='400' Height='600'
					 xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'
					 xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
					 xmlns:controls='using:Microsoft.UI.Xaml.Controls'>
					<ScrollViewer Width='400' Height='400' x:Name='scrollviewer'>
						<controls:ItemsRepeater x:Name='repeater'>
							<DataTemplate>
								<StackPanel>
									<controls:ItemsRepeater ItemsSource='{Binding}'>
										<controls:ItemsRepeater.Layout>
											<controls:StackLayout Orientation='Horizontal' />
										</controls:ItemsRepeater.Layout>
									</controls:ItemsRepeater>
								</StackPanel>
							</DataTemplate>
						</controls:ItemsRepeater>
					</ScrollViewer>
				</controls:ItemsRepeaterScrollHost>"                );

                rootRepeater              = (ItemsRepeater)scrollhost.FindName("repeater");
                scrollViewer              = (ScrollViewer)scrollhost.FindName("scrollviewer");
                scrollViewer.ViewChanged += (sender, args) =>
                {
                    if (!args.IsIntermediate)
                    {
                        viewChanged.Set();
                    }
                };

                List <List <int> > items = new List <List <int> >();
                for (int i = 0; i < 100; i++)
                {
                    items.Add(Enumerable.Range(0, 4).ToList());
                }
                rootRepeater.ItemsSource = items;
                Content = scrollhost;
            });

            // scroll down several times and validate no crash
            for (int i = 1; i < 5; i++)
            {
                IdleSynchronizer.Wait();
                RunOnUIThread.Execute(() =>
                {
                    scrollViewer.ChangeView(null, i * 200, null);
                });

                Verify.IsTrue(viewChanged.WaitOne(DefaultWaitTimeInMS));
                viewChanged.Reset();
            }
        }
Exemple #6
0
        public void VerifyCurrentAnchor()
        {
            //if (PlatformConfiguration.IsDebugBuildConfiguration())
            //{
            //	// Test is failing in chk configuration due to:
            //	// Bug #1726 Test Failure: RepeaterTests.VerifyCurrentAnchor
            //	Log.Warning("Skipping test for Debug builds.");
            //	return;
            //}

            ItemsRepeater           rootRepeater = null;
            ScrollViewer            scrollViewer = null;
            ItemsRepeaterScrollHost scrollhost   = null;
            ManualResetEvent        viewChanged  = new ManualResetEvent(false);

            RunOnUIThread.Execute(() =>
            {
                scrollhost = (ItemsRepeaterScrollHost)XamlReader.Load(
                    @"<controls:ItemsRepeaterScrollHost Width='400' Height='600'
					 xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'
					 xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
					 xmlns:controls='using:Microsoft.UI.Xaml.Controls'>
					<controls:ItemsRepeaterScrollHost.Resources>
						<DataTemplate x:Key='ItemTemplate' >
							<TextBlock Text='{Binding}' Height='50'/>
						</DataTemplate>
					</controls:ItemsRepeaterScrollHost.Resources>
					<ScrollViewer x:Name='scrollviewer'>
						<controls:ItemsRepeater x:Name='rootRepeater' ItemTemplate='{StaticResource ItemTemplate}' VerticalCacheLength='0' />
					</ScrollViewer>
				</controls:ItemsRepeaterScrollHost>"                );

                rootRepeater              = (ItemsRepeater)scrollhost.FindName("rootRepeater");
                scrollViewer              = (ScrollViewer)scrollhost.FindName("scrollviewer");
                scrollViewer.ViewChanged += (sender, args) =>
                {
                    if (!args.IsIntermediate)
                    {
                        viewChanged.Set();
                    }
                };

                rootRepeater.ItemsSource = Enumerable.Range(0, 500);
                Content = scrollhost;
            });

            // scroll down several times and validate current anchor
            for (int i = 1; i < 10; i++)
            {
                IdleSynchronizer.Wait();
                RunOnUIThread.Execute(() =>
                {
                    scrollViewer.ChangeView(null, i * 200, null);
                });

                Verify.IsTrue(viewChanged.WaitOne(DefaultWaitTimeInMS));
                viewChanged.Reset();
                IdleSynchronizer.Wait();

                RunOnUIThread.Execute(() =>
                {
                    Verify.AreEqual(i * 200, scrollViewer.VerticalOffset);
                    var anchor = PlatformConfiguration.IsOSVersionLessThan(OSVersion.Redstone5) ?
                                 scrollhost.CurrentAnchor :
                                 scrollViewer.CurrentAnchor;
                    var anchorIndex = rootRepeater.GetElementIndex(anchor);
                    Log.Comment("CurrentAnchor: " + anchorIndex);
                    Verify.AreEqual(i * 4, anchorIndex);
                });
            }
        }