コード例 #1
0
        [TestProperty("Ignore", "True")] // TODO 19581880: Re-enable after investigating and fixing the test failures.
#endif
        public void ValidateDataTemplateSelectorAsItemTemplate()
        {
            RunOnUIThread.Execute(() =>
            {
                var dataTemplateOdd = (DataTemplate)XamlReader.Load(
                    @"<DataTemplate  xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'>
                            <TextBlock Text='{Binding}' Height='30' />
                        </DataTemplate>");
                var dataTemplateEven = (DataTemplate)XamlReader.Load(
                    @"<DataTemplate  xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'>
                            <TextBlock Text='{Binding}' Height='40' />
                        </DataTemplate>");
                ItemsRepeater repeater = null;
                const int numItems     = 10;
                var selector           = new MySelector()
                {
                    TemplateOdd  = dataTemplateOdd,
                    TemplateEven = dataTemplateEven
                };

                Content = CreateAndInitializeRepeater
                          (
                    itemsSource: Enumerable.Range(0, numItems),
                    elementFactory: selector,
                    layout: new StackLayout(),
                    repeater: ref repeater
                          );

                Content.UpdateLayout();
                Verify.AreEqual(numItems, VisualTreeHelper.GetChildrenCount(repeater));
                for (int i = 0; i < numItems; i++)
                {
                    var element = (TextBlock)repeater.TryGetElement(i);
                    Verify.AreEqual(i.ToString(), element.Text);
                    Verify.AreEqual(i % 2 == 0 ? 40 : 30, element.Height);
                }

                repeater.ItemsSource = null;
                Content.UpdateLayout();

                // All the created items should be in the recycle pool now.
                var oddPool     = RecyclePool.GetPoolInstance(dataTemplateOdd);
                var oddElements = GetAllElementsFromPool(oddPool);
                Verify.AreEqual(5, oddElements.Count);
                foreach (var element in oddElements)
                {
                    Verify.AreEqual(30, ((TextBlock)element).Height);
                }

                var evenPool     = RecyclePool.GetPoolInstance(dataTemplateEven);
                var evenElements = GetAllElementsFromPool(evenPool);
                Verify.AreEqual(5, evenElements.Count);
                foreach (var element in evenElements)
                {
                    Verify.AreEqual(40, ((TextBlock)element).Height);
                }
            });
        }
コード例 #2
0
        public void ValidateCorrectSizeWhenEmptyDataTemplateInSelector()
        {
            RunOnUIThread.Execute(() =>
            {
                var dataTemplateOdd = (DataTemplate)XamlReader.Load(
                    @"<DataTemplate xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'>
							<TextBlock Text='{Binding}' Height='30' Width='50' />
						</DataTemplate>"                        );
                var dataTemplateEven = (DataTemplate)XamlReader.Load(
                    @"<DataTemplate  xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'><Border Height='0' /></DataTemplate>");
                ItemsRepeater repeater = null;
                const int numItems     = 10;
                var selector           = new MySelector()
                {
                    TemplateOdd  = dataTemplateOdd,
                    TemplateEven = dataTemplateEven
                };

                repeater = new ItemsRepeater()
                {
                    ItemTemplate = selector,
                    Layout       = new StackLayout(),
                    ItemsSource  = Enumerable.Range(0, numItems)
                };

                repeater.VerticalAlignment   = VerticalAlignment.Top;
                repeater.HorizontalAlignment = HorizontalAlignment.Left;
                Content = repeater;

                Content.UpdateLayout();
                Verify.AreEqual(numItems, VisualTreeHelper.GetChildrenCount(repeater));
                for (int i = 0; i < numItems; i++)
                {
                    var element = (FrameworkElement)repeater.TryGetElement(i);
                    if (i % 2 == 0)
                    {
                        Verify.AreEqual(element.Height, 0);
                    }
                    else
                    {
                        Verify.AreEqual(element.Height, 30);
                    }
                }

                Verify.AreEqual(5 * 30, repeater.ActualHeight);

                // ItemsRepeater stretches page, so actual width is width of page and not 50
                //Verify.AreEqual(50, repeater.ActualWidth);


                repeater.ItemsSource = null;
                Content.UpdateLayout();
            });
        }
コード例 #3
0
ファイル: ItemTemplateTests.cs プロジェクト: jamesmcroft/uno
        public async Task ValidateDataTemplateSelectorAsItemTemplate()
        {
            await RunOnUIThread.ExecuteAsync(async() =>
            {
                var dataTemplateOdd = (DataTemplate)XamlReader.Load(
                    @"<DataTemplate  xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'>
							<TextBlock Text='{Binding}' Height='30' />
						</DataTemplate>"                        );
                var dataTemplateEven = (DataTemplate)XamlReader.Load(
                    @"<DataTemplate  xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'>
							<TextBlock Text='{Binding}' Height='40' />
						</DataTemplate>"                        );
                ItemsRepeater repeater = null;
                const int numItems     = 10;
                var selector           = new MySelector()
                {
                    TemplateOdd  = dataTemplateOdd,
                    TemplateEven = dataTemplateEven
                };

                Content = CreateAndInitializeRepeater
                          (
                    itemsSource: Enumerable.Range(0, numItems),
                    elementFactory: selector,
                    layout: new StackLayout(),
                    repeater: ref repeater
                          );

                await UpdateLayoutWithWaitAsync();
                Verify.AreEqual(numItems, VisualTreeHelper.GetChildrenCount(repeater));
                for (int i = 0; i < numItems; i++)
                {
                    var element = (TextBlock)repeater.TryGetElement(i);
                    Verify.AreEqual(i.ToString(), element.Text);
                    Verify.AreEqual(i % 2 == 0 ? 40 : 30, element.Height);
                }

                repeater.ItemsSource = null;
                await UpdateLayoutWithWaitAsync();

                // In versions below RS5 we faked the recycling behaivor on data template
                // so we can get to the recycle pool that we addded internally in ItemsRepeater.
                if (PlatformConfiguration.IsOSVersionLessThan(OSVersion.Redstone5))
                {
                    // All the created items should be in the recycle pool now.
                    var oddPool     = RecyclePool.GetPoolInstance(dataTemplateOdd);
                    var oddElements = GetAllElementsFromPool(oddPool);
                    Verify.AreEqual(5, oddElements.Count);
                    foreach (var element in oddElements)
                    {
                        Verify.AreEqual(30, ((TextBlock)element).Height);
                    }

                    var evenPool     = RecyclePool.GetPoolInstance(dataTemplateEven);
                    var evenElements = GetAllElementsFromPool(evenPool);
                    Verify.AreEqual(5, evenElements.Count);
                    foreach (var element in evenElements)
                    {
                        Verify.AreEqual(40, ((TextBlock)element).Height);
                    }
                }
            });
        }