protected override UIElement GetElementCore(ElementFactoryGetArgs args)
        {
            int index = RepeaterTestHooks.GetElementFactoryElementIndex(args);

            _recordedGetElementCalls.Add(new GetElementCallInfo(index, args.Parent));
            return(GetElementFunc != null?GetElementFunc(index, args.Parent) : null);
        }
Пример #2
0
        public async Task ValidateReyclingElementFactoryWithNoTemplate()
        {
            await RunOnUIThread.ExecuteAsync(async() =>
            {
                var elementFactory = new RecyclingElementFactoryDerived()
                {
                    RecyclePool = new RecyclePool()
                };

                Verify.Throws <
#if HAS_UNO // Uno throws a more specific exception
                    InvalidOperationException
#else
                    COMException
#endif
                    >(delegate
                {
                    var context    = (ElementFactoryGetArgs)RepeaterTestHooks.CreateRepeaterElementFactoryGetArgs();
                    context.Parent = null;
                    context.Data   = 0;

                    elementFactory.GetElement(context);
                });
            });
        }
Пример #3
0
        public static void OnRendering(object snd, object args)
        {
            bool budgetReached = ShouldYield();

            if (!budgetReached && m_pendingWork.Count > 0)
            {
                // Sort in descending order of priority and work from the end of the list to avoid moving around during erase.
                m_pendingWork.Sort((lhs, rhs) => lhs.Priority - rhs.Priority);
                int currentIndex = (int)(m_pendingWork.Count) - 1;

                do
                {
                    m_pendingWork[currentIndex].InvokeWorkFunc();
                    m_pendingWork.RemoveAt(currentIndex);
                } while (--currentIndex >= 0 && !ShouldYield());
            }

            if (m_pendingWork.Count == 0)
            {
                // No more pending work, unhook from rendering event since being hooked up will case wux to try to
                // call the event at 60 frames per second
                m_renderingToken = false;
                Windows.UI.Xaml.Media.CompositionTarget.Rendering -= OnRendering;
                RepeaterTestHooks.NotifyBuildTreeCompleted();
            }

            // Reset the timer so it snaps the time just before rendering
            m_timer.Reset();
        }
Пример #4
0
        public void ValidateReyclingElementFactoryWithNoTemplate()
        {
            RunOnUIThread.Execute(() =>
            {
                var elementFactory = new RecyclingElementFactoryDerived()
                {
                    RecyclePool = new RecyclePool()
                };

                Verify.Throws <COMException>(delegate
                {
                    var context    = (ElementFactoryGetArgs)RepeaterTestHooks.CreateRepeaterElementFactoryGetArgs();
                    context.Parent = null;
                    context.Data   = 0;

                    elementFactory.GetElement(context);
                });
            });
        }
        protected override UIElement GetElementCore(ElementFactoryGetArgs context)
        {
            UIElement element = base.GetElementCore(context);
            int       index   = RepeaterTestHooks.GetElementFactoryElementIndex(context);

            if (GetElementFunc != null)
            {
                element = GetElementFunc(index, context.Parent, element);
            }

            if (!RealizedElementIndices.Contains(index))
            {
                _realizedElements.Add(element);
                _realizedElementIndices.Add(index);
            }
            else if (ValidateElementIndices)
            {
                throw new InvalidOperationException("Cannot request an element that has already been realized.");
            }

            return(element);
        }
Пример #6
0
        public void ValidateRecycling()
        {
            RunOnUIThread.Execute(() =>
            {
                var elementFactory = new RecyclingElementFactory()
                {
                    RecyclePool = new RecyclePool(),
                };
                elementFactory.Templates["even"] = (DataTemplate)XamlReader.Load(
                    @"<DataTemplate  xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'>
						<TextBlock Text='even' />
					</DataTemplate>"                    );
                elementFactory.Templates["odd"] = (DataTemplate)XamlReader.Load(
                    @"<DataTemplate  xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'>
						<TextBlock Text='odd' />
					</DataTemplate>"                    );

                elementFactory.SelectTemplateKey +=
                    delegate(RecyclingElementFactory sender, SelectTemplateEventArgs args)
                {
                    args.TemplateKey = ((int)args.DataContext % 2 == 0) ? "even" : "odd";
                };

                const int numItems     = 10;
                ItemsRepeater repeater = new ItemsRepeater()
                {
                    ItemsSource  = Enumerable.Range(0, numItems),
                    ItemTemplate = elementFactory,
                };

                var context         = (ElementFactoryGetArgs)RepeaterTestHooks.CreateRepeaterElementFactoryGetArgs();
                context.Parent      = repeater;
                var clearContext    = (ElementFactoryRecycleArgs)RepeaterTestHooks.CreateRepeaterElementFactoryRecycleArgs();
                clearContext.Parent = repeater;

                // Element0 is of type even, a new one should be created
                context.Data = 0;
                var element0 = elementFactory.GetElement(context);
                Verify.IsNotNull(element0);
                Verify.AreEqual("even", (element0 as TextBlock).Text);
                clearContext.Element = element0;
                elementFactory.RecycleElement(clearContext);

                // Element1 is of type odd, a new one should be created
                context.Data = 1;
                var element1 = elementFactory.GetElement(context);
                Verify.IsNotNull(element1);
                Verify.AreNotSame(element0, element1);
                Verify.AreEqual("odd", (element1 as TextBlock).Text);
                clearContext.Element = element1;
                elementFactory.RecycleElement(clearContext);

                // Element0 should be recycled for element2
                context.Data = 2;
                var element2 = elementFactory.GetElement(context);
                Verify.AreEqual("even", (element2 as TextBlock).Text);
                Verify.AreSame(element0, element2);

                // Element1 should be recycled for element3
                context.Data = 3;
                var element3 = elementFactory.GetElement(context);
                Verify.AreEqual("odd", (element3 as TextBlock).Text);
                Verify.AreSame(element1, element3);
            });
        }