Beispiel #1
0
        private void SetupVisiblePlacementWidth(IEnumerable <DependencyObject> visualAncestry)
        {
            var parent = visualAncestry.OfType <Panel>().ElementAt(1);

            VisiblePlacementWidth = TreeHelper.GetVisibleWidth((FrameworkElement)PlacementTarget, parent);
        }
Beispiel #2
0
        private CustomPopupPlacement[] ComboBoxCustomPopupPlacementCallback(Size popupSize, Size targetSize,
                                                                            Point offset)
        {
            var locationFromScreen = this.PlacementTarget.PointToScreen(new Point(0, 0));

            var mainVisual = PlacementTarget.GetVisualAncestry().OfType <Visual>().LastOrDefault();

            if (mainVisual == null)
            {
                return(new CustomPopupPlacement[0]);
            }

            var screenWidth  = (int)DpiHelper.TransformToDeviceX(mainVisual, SystemParameters.PrimaryScreenWidth);
            var screenHeight = (int)DpiHelper.TransformToDeviceY(mainVisual, SystemParameters.PrimaryScreenHeight);

            var locationX = (int)locationFromScreen.X % screenWidth;
            var locationY = (int)locationFromScreen.Y % screenHeight;

            var realOffsetX = (popupSize.Width - targetSize.Width) / 2.0;

            double    offsetX;
            const int rtlHorizontalOffset = 20;

            if (FlowDirection == FlowDirection.LeftToRight)
            {
                offsetX = DpiHelper.TransformToDeviceX(mainVisual, offset.X);
            }
            else
            {
                offsetX = DpiHelper.TransformToDeviceX(mainVisual,
                                                       offset.X - targetSize.Width - rtlHorizontalOffset);
            }

            var defaultVerticalOffsetIndepent = DpiHelper.TransformToDeviceY(mainVisual, DefaultVerticalOffset);
            var upVerticalOffsetIndepent      = DpiHelper.TransformToDeviceY(mainVisual, UpVerticalOffset);
            var downVerticalOffsetIndepent    = DpiHelper.TransformToDeviceY(mainVisual, DownVerticalOffset);
            var parent = this.PlacementTarget.GetVisualAncestry().OfType <Panel>().ElementAt(1);

            VisiblePlacementWidth = TreeHelper.GetVisibleWidth((FrameworkElement)PlacementTarget, parent);

            if (locationX + popupSize.Width - realOffsetX > screenWidth ||
                locationX + realOffsetX < 0)
            {
                SetChildTemplateIfNeed(DefaultContentTemplate);

                var newY = locationY + popupSize.Height > screenHeight
                    ? -(defaultVerticalOffsetIndepent + popupSize.Height)
                    : defaultVerticalOffsetIndepent + targetSize.Height;

                return(new[] { new CustomPopupPlacement(new Point(offsetX, newY), PopupPrimaryAxis.Horizontal) });
            }
            if (locationY + popupSize.Height > screenHeight)
            {
                SetChildTemplateIfNeed(UpContentTemplate);

                var newY = upVerticalOffsetIndepent - popupSize.Height + targetSize.Height;

                return(new[] { new CustomPopupPlacement(new Point(offsetX, newY), PopupPrimaryAxis.None) });
            }
            else
            {
                SetChildTemplateIfNeed(DownContentTemplate);

                var newY = downVerticalOffsetIndepent;

                return(new[] { new CustomPopupPlacement(new Point(offsetX, newY), PopupPrimaryAxis.None) });
            }
        }