Exemplo n.º 1
0
        private void InsertByDockPosition(LayoutContext layoutContext, System.Windows.Controls.Dock?defaultPosition = null)
        {
            Debug.Assert(!IsIdle);

            if (LayoutContexts.Count > 1)
            {
                //  See if the visual has a DockPosition property. If so, automatically
                //  position the child.

                LayoutContext reference = (LayoutContexts[0] == layoutContext ? LayoutContexts[1] : LayoutContexts[0]);
                System.Windows.Controls.Dock?dockPosition = GetDockPosition(layoutContext.DockableCollection);
                switch (dockPosition ?? defaultPosition)
                {
                case null:
                    break;

                case System.Windows.Controls.Dock.Bottom:
                    layoutContext.DockableCollection.HorizontalContentAlignment = HorizontalAlignment.Stretch;
                    layoutContext.InsertBottom(reference);
                    break;

                case System.Windows.Controls.Dock.Left:
                    layoutContext.DockableCollection.VerticalContentAlignment = VerticalAlignment.Stretch;
                    layoutContext.InsertLeft(reference);
                    break;

                case System.Windows.Controls.Dock.Right:
                    layoutContext.DockableCollection.VerticalContentAlignment = VerticalAlignment.Stretch;
                    layoutContext.InsertRight(reference);
                    break;

                case System.Windows.Controls.Dock.Top:
                    layoutContext.DockableCollection.HorizontalContentAlignment = HorizontalAlignment.Stretch;
                    layoutContext.InsertTop(reference);
                    break;

                default:
                    throw new ArgumentException("Invalid value: " + (dockPosition.HasValue ? dockPosition.Value.ToString() : "<null>"), "DockPosition");
                }
            }
        }
Exemplo n.º 2
0
        internal void InsertByLocation(DockableCollection visual, Rect bounds, System.Windows.Controls.Dock defaultPosition)
        {
            using (new Activity(this))
            {
                LayoutContext layoutContext = GetLayoutContext(visual);
                LayoutContext reference     = (LayoutContexts[0] == layoutContext ? LayoutContexts[1] : LayoutContexts[0]);

                //  If the dock resized (smaller) and the bounds are outside the dock, position the visual at the right or bottom edge

                if (bounds.Left >= ActualWidth)
                {
                    layoutContext.InsertRight(reference);
                }
                else if (bounds.Top >= ActualHeight)
                {
                    layoutContext.InsertBottom(reference);
                }
                else
                {
                    //  Find the visual where the new visual's midpoint was

                    double        centerX           = (bounds.Left + bounds.Right) / 2;
                    double        centerY           = (bounds.Top + bounds.Bottom) / 2;
                    LayoutContext midpointReference = FindMidPoint(centerX, centerY);
                    if (midpointReference == null)
                    {
                        //  The midpoint is outside the dock

                        InsertByDockPosition(layoutContext, defaultPosition);
                    }
                    else
                    {
                        //  Position the visual relative to this reference

                        double referenceX = (midpointReference.Left.Value + midpointReference.Right.Value) / 2;
                        double referenceY = (midpointReference.Top.Value + midpointReference.Bottom.Value) / 2;

                        if (Math.Abs(centerX - referenceX) < MinimumChildSize.Width / 2)
                        {
                            if (centerY < referenceY)
                            {
                                midpointReference.InsertAbove(layoutContext);
                            }
                            else
                            {
                                midpointReference.InsertBelow(layoutContext);
                            }
                        }
                        else if (Math.Abs(centerY - referenceY) < MinimumChildSize.Height / 2)
                        {
                            if (centerX < referenceX)
                            {
                                midpointReference.InsertToLeftOf(layoutContext);
                            }
                            else
                            {
                                midpointReference.InsertToRightOf(layoutContext);
                            }
                        }
                        else
                        {
                            midpointReference.InsertBelow(layoutContext);
                        }
                    }
                }
            }
        }