Example #1
0
        private void MenuFlyout_Opened(object sender, object e)
        {
            if (_parentMenu.UpdateMenuItemsFlyoutPlacement() && !_menuFlyoutPlacementChanged)
            {
                _menuFlyoutPlacementChanged = true;
                ShowMenu();
            }

            _parentMenu.CalculateBounds();
            IsOpened = true;
            VisualStateManager.GoToState(this, "Opened", true);
            _parentMenu.IsInTransitionState = false;

            if (!_menuFlyoutRepositioned)
            {
                var popup = VisualTreeHelper.GetOpenPopups(Window.Current).FirstOrDefault(p => p.Child is MenuFlyoutPresenter);

                if (popup != null)
                {
                    var mfp    = (MenuFlyoutPresenter)popup.Child;
                    var height = mfp.ActualHeight;
                    var width  = mfp.ActualWidth;

                    var flytoutButtonPoint = FlyoutButton.TransformToVisual(Window.Current.Content).TransformPoint(new Point(0, 0));

                    if ((width > Window.Current.Bounds.Width - flytoutButtonPoint.X &&
                         (MenuFlyout.Placement == FlyoutPlacementMode.Bottom)) ||
                        (height > Window.Current.Bounds.Height - flytoutButtonPoint.Y &&
                         (MenuFlyout.Placement == FlyoutPlacementMode.Right)))
                    {
                        ShowMenuRepositioned(width, height);
                    }
                }
            }
        }
        private void MenuFlyout_Opened(object sender, object e)
        {
            if (_parentMenu.UpdateMenuItemsFlyoutPlacement() && !_menuFlyoutPlacementChanged)
            {
                _menuFlyoutPlacementChanged = true;
                ShowMenu();
            }

            _parentMenu.CalculateBounds();
            IsOpened = true;
            VisualStateManager.GoToState(this, "Opened", true);
            _parentMenu.IsInTransitionState = false;

            if (!_menuFlyoutRepositioned)
            {
                IReadOnlyList <Popup> popups;
                UIElement             content;
                double outerContentWidth;
                double outerContentHeight;
#if !HAS_UNO
                if (ControlHelpers.IsXamlRootAvailable && MenuFlyout.XamlRoot != null)
                {
                    popups             = VisualTreeHelper.GetOpenPopupsForXamlRoot(MenuFlyout.XamlRoot);
                    content            = MenuFlyout.XamlRoot.Content;
                    outerContentWidth  = MenuFlyout.XamlRoot.Size.Width;
                    outerContentHeight = MenuFlyout.XamlRoot.Size.Height;
                }
                else
#endif
                {
                    popups             = VisualTreeHelper.GetOpenPopups(Windows.UI.Xaml.Window.Current);
                    content            = Windows.UI.Xaml.Window.Current.Content;
                    outerContentWidth  = Windows.UI.Xaml.Window.Current.Bounds.Width;
                    outerContentHeight = Windows.UI.Xaml.Window.Current.Bounds.Height;
                }

                var popup = popups.FirstOrDefault(p => p.Child is MenuFlyoutPresenter);

                if (popup != null)
                {
                    var mfp    = (MenuFlyoutPresenter)popup.Child;
                    var height = mfp.ActualHeight;
                    var width  = mfp.ActualWidth;

                    var flytoutButtonPoint = FlyoutButton.TransformToVisual(content).TransformPoint(new Point(0, 0));

                    if ((width > outerContentWidth - flytoutButtonPoint.X &&
                         (MenuFlyout.Placement == FlyoutPlacementMode.Bottom)) ||
                        (height > outerContentHeight - flytoutButtonPoint.Y &&
                         (MenuFlyout.Placement == FlyoutPlacementMode.Right)))
                    {
                        ShowMenuRepositioned(width, height);
                    }
                }
            }
        }