public void VerifyFlyoutCommandsArePropagatedToTheCommandBar()
        {
            /*
             * if (PlatformConfiguration.IsOSVersionLessThan(OSVersion.Redstone2))
             * {
             *  Log.Warning("Test is disabled pre-RS2 because CommandBarFlyout is not supported pre-RS2");
             *  return;
             * }
             */

            CommandBarFlyout commandBarFlyout       = null;
            Button           commandBarFlyoutTarget = null;

            SetupCommandBarFlyoutTest(out commandBarFlyout, out commandBarFlyoutTarget);
            OpenFlyout(commandBarFlyout, commandBarFlyoutTarget);

            RunOnUIThread.Execute(() =>
            {
                Popup flyoutPopup     = GetFlyoutPopup();
                CommandBar commandBar = TestUtilities.FindDescendents <CommandBar>(flyoutPopup).Single();

                Verify.AreEqual(commandBarFlyout.PrimaryCommands.Count, commandBar.PrimaryCommands.Count);

                for (int i = 0; i < commandBarFlyout.PrimaryCommands.Count; i++)
                {
                    Verify.AreEqual(commandBarFlyout.PrimaryCommands[i], commandBar.PrimaryCommands[i]);
                }

                Verify.AreEqual(commandBarFlyout.SecondaryCommands.Count, commandBar.SecondaryCommands.Count);

                for (int i = 0; i < commandBarFlyout.SecondaryCommands.Count; i++)
                {
                    Verify.AreEqual(commandBarFlyout.SecondaryCommands[i], commandBar.SecondaryCommands[i]);
                }
            });

            CloseFlyout(commandBarFlyout);
        }
        public void VerifyPrimaryCommandsCanOverflowToSecondaryItemsControl()
        {
            /*
             * if (PlatformConfiguration.IsOSVersionLessThan(OSVersion.Redstone2))
             * {
             *  Log.Warning("Test is disabled pre-RS2 because CommandBarFlyout is not supported pre-RS2");
             *  return;
             * }
             */

            CommandBarFlyout flyout       = null;
            Button           flyoutTarget = null;

            RunOnUIThread.Execute(() =>
            {
                flyout = new CommandBarFlyout()
                {
                    Placement = FlyoutPlacementMode.Right
                };

                flyout.PrimaryCommands.Add(new AppBarButton()
                {
                    Label = "Item 1"
                });
                flyout.PrimaryCommands.Add(new AppBarButton()
                {
                    Label = "Item 2"
                });
                flyout.PrimaryCommands.Add(new AppBarButton()
                {
                    Label = "Item 3"
                });
                flyout.PrimaryCommands.Add(new AppBarButton()
                {
                    Label = "Item 4"
                });
                flyout.PrimaryCommands.Add(new AppBarButton()
                {
                    Label = "Item 5"
                });
                flyout.PrimaryCommands.Add(new AppBarButton()
                {
                    Label = "Item 6"
                });
                flyout.PrimaryCommands.Add(new AppBarButton()
                {
                    Label = "Item 7"
                });
                flyout.PrimaryCommands.Add(new AppBarButton()
                {
                    Label = "Item 8"
                });
                flyout.PrimaryCommands.Add(new AppBarButton()
                {
                    Label = "Item 9"
                });
                flyout.PrimaryCommands.Add(new AppBarButton()
                {
                    Label = "Item 10"
                });
                flyout.PrimaryCommands.Add(new AppBarButton()
                {
                    Label = "Item 11"
                });
                flyout.PrimaryCommands.Add(new AppBarButton()
                {
                    Label = "Item 12"
                });
                flyout.PrimaryCommands.Add(new AppBarButton()
                {
                    Label = "Item 13"
                });
                flyout.PrimaryCommands.Add(new AppBarButton()
                {
                    Label = "Item 14"
                });
                flyout.PrimaryCommands.Add(new AppBarButton()
                {
                    Label = "Item 15"
                });
                flyout.PrimaryCommands.Add(new AppBarButton()
                {
                    Label = "Item 16"
                });
                flyout.PrimaryCommands.Add(new AppBarButton()
                {
                    Label = "Item 17"
                });
                flyout.PrimaryCommands.Add(new AppBarButton()
                {
                    Label = "Item 18"
                });
                flyout.PrimaryCommands.Add(new AppBarButton()
                {
                    Label = "Item 19"
                });
                flyout.PrimaryCommands.Add(new AppBarButton()
                {
                    Label = "Item 20"
                });

                flyout.SecondaryCommands.Add(new AppBarButton()
                {
                    Label = "Item 21"
                });
                flyout.SecondaryCommands.Add(new AppBarButton()
                {
                    Label = "Item 22"
                });
                flyout.SecondaryCommands.Add(new AppBarButton()
                {
                    Label = "Item 23"
                });
                flyout.SecondaryCommands.Add(new AppBarButton()
                {
                    Label = "Item 24"
                });
                flyout.SecondaryCommands.Add(new AppBarButton()
                {
                    Label = "Item 25"
                });

                flyoutTarget = new Button()
                {
                    Content = "Click for flyout"
                };
                Content = flyoutTarget;
                Content.UpdateLayout();
            });

            OpenFlyout(flyout, flyoutTarget);

            RunOnUIThread.Execute(() =>
            {
                Popup flyoutPopup     = VisualTreeHelperEx.GetOpenPopups(WindowEx.Current).Reverse().Skip(1).First();
                CommandBar commandBar = TestUtilities.FindDescendents <CommandBar>(flyoutPopup).Single();

                IList <ItemsControl> itemsControls = TestUtilities.FindDescendents <ItemsControl>(commandBar);

                Log.Comment("We expect there to be 2 ItemsControls inside the CommandBar; {0} were found.", itemsControls.Count);
                Verify.AreEqual(2, itemsControls.Count);

                ItemsControl primaryItemsControl   = itemsControls[0];
                ItemsControl secondaryItemsControl = itemsControls[1];

                Log.Comment("We expect there to be 9 items located inside the primary ItemsControl; {0} were found.", primaryItemsControl.Items.Count);
                Verify.AreEqual(9, primaryItemsControl.Items.Count);
                Log.Comment("We expect there to be 17 items located inside the secondary ItemsControl (16 + autogenerated separator); {0} were found.", secondaryItemsControl.Items.Count);
                Verify.AreEqual(17, secondaryItemsControl.Items.Count);
            });

            CloseFlyout(flyout);
        }
        private void VerifyCommandBarSizing(CommandBarSizingOptions sizingOptions)
        {
            CommandBarFlyout commandBarFlyout       = null;
            Button           commandBarFlyoutTarget = null;

            SetupCommandBarFlyoutTest(out commandBarFlyout, out commandBarFlyoutTarget);

            RunOnUIThread.Execute(() =>
            {
                switch (sizingOptions)
                {
                case CommandBarSizingOptions.SecondaryItemsLarger:
                    commandBarFlyout.SecondaryCommands.Add(new AppBarButton()
                    {
                        Label = "Item with a label wider than primary items"
                    });
                    break;

                case CommandBarSizingOptions.SecondaryItemsMaxWidth:
                    commandBarFlyout.SecondaryCommands.Add(new AppBarButton()
                    {
                        Label = "Item with a really really really long label that will not fit in the space provided"
                    });
                    break;

                case CommandBarSizingOptions.SecondaryItemsMaxHeight:
                    for (int i = 0; i < 20; i++)
                    {
                        commandBarFlyout.SecondaryCommands.Add(new AppBarButton()
                        {
                            Label = "Do another thing"
                        });
                    }
                    break;
                }
            });

            OpenFlyout(commandBarFlyout, commandBarFlyoutTarget);

            CommandBar commandBar = null;

            RunOnUIThread.Execute(() =>
            {
                Popup flyoutPopup = GetFlyoutPopup();
                commandBar        = TestUtilities.FindDescendents <CommandBar>(flyoutPopup).Single();
            });

            IdleSynchronizer.Wait();

            RunOnUIThread.Execute(() =>
            {
                // Pre-RS5, CommandBarFlyouts always open expanded, so to put us in a known good state,
                // we'll collapse the flyout before we do anything else.
                commandBar.IsOpen = false;
            });

            IdleSynchronizer.Wait();

            double originalWidth  = 0;
            double originalHeight = 0;

            RunOnUIThread.Execute(() =>
            {
                Popup flyoutPopup = GetFlyoutPopup();
                commandBar        = TestUtilities.FindDescendents <CommandBar>(flyoutPopup).Single();

                originalWidth  = commandBar.ActualWidth;
                originalHeight = commandBar.ActualHeight;

                commandBar.IsOpen = true;
            });

            IdleSynchronizer.Wait();

            RunOnUIThread.Execute(() =>
            {
                CommandBarOverflowPresenter overflowPresenter = TestUtilities.FindDescendents <CommandBarOverflowPresenter>(commandBar).Single();

                if (sizingOptions == CommandBarSizingOptions.PrimaryItemsLarger ||
                    sizingOptions == CommandBarSizingOptions.SecondaryItemsMaxHeight)
                {
                    Verify.AreEqual(originalWidth, commandBar.ActualWidth);
                    Verify.AreEqual(originalWidth, overflowPresenter.ActualWidth);
                }
                else
                {
                    Verify.IsLessThan(originalWidth, commandBar.ActualWidth);
                    Verify.AreEqual(overflowPresenter.ActualWidth, commandBar.ActualWidth);
                }

                Verify.AreEqual(originalHeight, commandBar.ActualHeight);

                if (sizingOptions == CommandBarSizingOptions.SecondaryItemsMaxWidth)
                {
                    Verify.AreEqual(commandBar.MaxWidth, commandBar.ActualWidth);
                }
                else if (sizingOptions == CommandBarSizingOptions.SecondaryItemsMaxHeight)
                {
                    Verify.AreEqual(overflowPresenter.MaxHeight, overflowPresenter.ActualHeight);
                }

                commandBar.IsOpen = false;
            });

            IdleSynchronizer.Wait();
            CloseFlyout(commandBarFlyout);
        }