public void VerifyPropertyValuesAfterTemplateApplication()
        {
            if (PlatformConfiguration.IsOSVersionLessThan(OSVersion.Redstone2))
            {
                Log.Warning("Test is disabled on pre-RS2 because ScrollViewer not supported pre-RS2");
                return;
            }

            using (PrivateLoggingHelper privateSVLoggingHelper = new PrivateLoggingHelper("ScrollViewer", "Scroller"))
            {
                ScrollViewer   scrollViewer = null;
                Rectangle      rectangleScrollViewerContent = null;
                AutoResetEvent scrollViewerLoadedEvent      = new AutoResetEvent(false);
                AutoResetEvent scrollViewerUnloadedEvent    = new AutoResetEvent(false);

                RunOnUIThread.Execute(() =>
                {
                    rectangleScrollViewerContent = new Rectangle();
                    scrollViewer = new ScrollViewer();

                    SetupDefaultUI(scrollViewer, rectangleScrollViewerContent, scrollViewerLoadedEvent, scrollViewerUnloadedEvent);
                });

                WaitForEvent("Waiting for Loaded event", scrollViewerLoadedEvent);

                RunOnUIThread.Execute(() =>
                {
                    Log.Comment("Verifying ScrollViewer property values after Loaded event");
                    Verify.AreEqual(scrollViewer.Content, rectangleScrollViewerContent);
                    Verify.IsNotNull(ScrollViewerTestHooks.GetScrollerPart(scrollViewer));
                    Verify.AreEqual(ScrollViewerTestHooks.GetScrollerPart(scrollViewer).Content, rectangleScrollViewerContent);
                    Verify.IsNotNull(scrollViewer.HorizontalScrollController);
                    Verify.IsNotNull(scrollViewer.VerticalScrollController);
                    Verify.AreEqual(scrollViewer.ExtentWidth, c_defaultUIScrollViewerContentWidth);
                    Verify.AreEqual(scrollViewer.ExtentHeight, c_defaultUIScrollViewerContentHeight);
                    Verify.AreEqual(scrollViewer.ViewportWidth, c_defaultUIScrollViewerWidth);
                    Verify.AreEqual(scrollViewer.ViewportHeight, c_defaultUIScrollViewerHeight);
                    Verify.AreEqual(scrollViewer.ScrollableWidth, c_defaultUIScrollViewerContentWidth - c_defaultUIScrollViewerWidth);
                    Verify.AreEqual(scrollViewer.ScrollableHeight, c_defaultUIScrollViewerContentHeight - c_defaultUIScrollViewerHeight);

                    Log.Comment("Resetting window content and ScrollViewer");
                    MUXControlsTestApp.App.TestContentRoot = null;
                    scrollViewer = null;
                });

                WaitForEvent("Waiting for Unloaded event", scrollViewerUnloadedEvent);

                IdleSynchronizer.Wait();
                Log.Comment("Garbage collecting...");
                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
                Log.Comment("Done");
            }
        }
        public void VerifyDefaultPropertyValues()
        {
            if (PlatformConfiguration.IsOSVersionLessThan(OSVersion.Redstone2))
            {
                Log.Warning("Test is disabled on pre-RS2 because ScrollViewer not supported pre-RS2");
                return;
            }

            RunOnUIThread.Execute(() =>
            {
                ScrollViewer scrollViewer = new ScrollViewer();
                Verify.IsNotNull(scrollViewer);

                Log.Comment("Verifying ScrollViewer default property values");
                Verify.IsNull(scrollViewer.Content);
                Verify.IsNull(ScrollViewerTestHooks.GetScrollerPart(scrollViewer));
                Verify.IsNull(scrollViewer.HorizontalScrollController);
                Verify.IsNull(scrollViewer.VerticalScrollController);
#if USE_SCROLLMODE_AUTO
                Verify.AreEqual(scrollViewer.ComputedHorizontalScrollMode, c_defaultComputedHorizontalScrollMode);
                Verify.AreEqual(scrollViewer.ComputedVerticalScrollMode, c_defaultComputedVerticalScrollMode);
#endif
                Verify.AreEqual(scrollViewer.IgnoredInputKind, c_defaultIgnoredInputKind);
                Verify.AreEqual(scrollViewer.ContentOrientation, c_defaultContentOrientation);
                Verify.AreEqual(scrollViewer.HorizontalScrollChainingMode, c_defaultHorizontalScrollChainingMode);
                Verify.AreEqual(scrollViewer.VerticalScrollChainingMode, c_defaultVerticalScrollChainingMode);
                Verify.AreEqual(scrollViewer.HorizontalScrollRailingMode, c_defaultHorizontalScrollRailingMode);
                Verify.AreEqual(scrollViewer.VerticalScrollRailingMode, c_defaultVerticalScrollRailingMode);
                Verify.AreEqual(scrollViewer.HorizontalScrollMode, c_defaultHorizontalScrollMode);
                Verify.AreEqual(scrollViewer.VerticalScrollMode, c_defaultVerticalScrollMode);
                Verify.AreEqual(scrollViewer.ZoomMode, c_defaultZoomMode);
                Verify.AreEqual(scrollViewer.ZoomChainingMode, c_defaultZoomChainingMode);
                Verify.IsGreaterThan(scrollViewer.MinZoomFactor, c_defaultMinZoomFactor - c_epsilon);
                Verify.IsLessThan(scrollViewer.MinZoomFactor, c_defaultMinZoomFactor + c_epsilon);
                Verify.IsGreaterThan(scrollViewer.MaxZoomFactor, c_defaultMaxZoomFactor - c_epsilon);
                Verify.IsLessThan(scrollViewer.MaxZoomFactor, c_defaultMaxZoomFactor + c_epsilon);
                Verify.AreEqual(scrollViewer.HorizontalAnchorRatio, c_defaultAnchorRatio);
                Verify.AreEqual(scrollViewer.VerticalAnchorRatio, c_defaultAnchorRatio);
                Verify.AreEqual(scrollViewer.ExtentWidth, 0.0);
                Verify.AreEqual(scrollViewer.ExtentHeight, 0.0);
                Verify.AreEqual(scrollViewer.ViewportWidth, 0.0);
                Verify.AreEqual(scrollViewer.ViewportHeight, 0.0);
                Verify.AreEqual(scrollViewer.ScrollableWidth, 0.0);
                Verify.AreEqual(scrollViewer.ScrollableHeight, 0.0);
            });
        }
        public void VerifyAnchorCandidateRegistration()
        {
            if (PlatformConfiguration.IsOSVersionLessThan(OSVersion.Redstone2))
            {
                Log.Warning("Test is disabled on pre-RS2 because ScrollViewer not supported pre-RS2");
                return;
            }

            using (PrivateLoggingHelper privateSVLoggingHelper = new PrivateLoggingHelper("ScrollViewer", "Scroller"))
            {
                int            expectedAnchorCandidatesCount = 0;
                Scroller       scroller     = null;
                ScrollViewer   scrollViewer = null;
                Rectangle      rectangleScrollViewerContent     = null;
                AutoResetEvent scrollViewerLoadedEvent          = new AutoResetEvent(false);
                AutoResetEvent scrollViewerAnchorRequestedEvent = new AutoResetEvent(false);

                RunOnUIThread.Execute(() =>
                {
                    rectangleScrollViewerContent = new Rectangle();
                    scrollViewer = new ScrollViewer();
                    scrollViewer.HorizontalAnchorRatio = 0.1;

                    SetupDefaultUI(scrollViewer, rectangleScrollViewerContent, scrollViewerLoadedEvent);

                    scrollViewer.AnchorRequested += (ScrollViewer sender, ScrollerAnchorRequestedEventArgs args) =>
                    {
                        Log.Comment("ScrollViewer.AnchorRequested event handler. args.AnchorCandidates.Count: " + args.AnchorCandidates.Count);
                        Verify.IsNull(args.AnchorElement);
                        Verify.AreEqual(expectedAnchorCandidatesCount, args.AnchorCandidates.Count);
                        scrollViewerAnchorRequestedEvent.Set();
                    };
                });

                WaitForEvent("Waiting for Loaded event", scrollViewerLoadedEvent);

                RunOnUIThread.Execute(() =>
                {
                    Log.Comment("Accessing inner Scroller control");
                    scroller = ScrollViewerTestHooks.GetScrollerPart(scrollViewer);

                    Log.Comment("Registering Rectangle as anchor candidate");
                    scrollViewer.RegisterAnchorCandidate(rectangleScrollViewerContent);
                    expectedAnchorCandidatesCount = 1;

                    Log.Comment("Forcing Scroller layout");
                    scroller.InvalidateArrange();
                });

                WaitForEvent("Waiting for AnchorRequested event", scrollViewerAnchorRequestedEvent);

                RunOnUIThread.Execute(() =>
                {
                    Log.Comment("Unregistering Rectangle as anchor candidate");
                    scrollViewer.UnregisterAnchorCandidate(rectangleScrollViewerContent);
                    expectedAnchorCandidatesCount = 0;

                    Log.Comment("Forcing Scroller layout");
                    scroller.InvalidateArrange();
                });

                WaitForEvent("Waiting for AnchorRequested event", scrollViewerAnchorRequestedEvent);
            }
        }