Esempio n. 1
0
        private static void OffsetPropertyMetadataChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            ArrowTip element = sender as ArrowTip;

            element.LayoutArrow();
        }
Esempio n. 2
0
        private void ArrangePopup()
        {
            if (((this.m_popup != null) && (this.m_targetElement != null)) && this.m_popup.IsOpen)
            {
                if ((m_popup.Child as ArrowTip).Content == null)
                {
                    object obj = this.Content;
                    this.Content = null;
                    (m_popup.Child as ArrowTip).Content = obj;
                }
                m_popup.UpdateLayout();
                ArrowTip tip = (m_popup.Child as ArrowTip);

                UserControl rootVisual   = Application.Current.RootVisual as UserControl;
                double      actualWidth  = rootVisual.ActualWidth;
                double      actualHeight = rootVisual.ActualHeight;
                double      targetWidth  = this.m_targetElement.ActualWidth;
                double      targetHeight = this.m_targetElement.ActualHeight;
                if (((actualHeight != 0.0) && (actualWidth != 0.0)) && ((targetWidth != 0.0) && (targetHeight != 0.0)))
                {
                    GeneralTransform transform = null;
                    try
                    {
                        transform = this.m_targetElement.TransformToVisual(rootVisual);
                    }
                    catch
                    {
                        //Don't need to do nothing.
                    }
                    if (transform != null)
                    {
                        Point point    = new Point(0.0, 0.0);
                        Point position = transform.Transform(point);

                        if (Orientation == TooltipOrientation.LeftOrRight)
                        {
                            bool isLeft = false;

                            if (position.X + tip.ActualWidth + targetWidth > actualWidth)
                            {
                                isLeft = true;
                            }

                            //左
                            if (isLeft)
                            {
                                tip.Orientation          = ArrowTipOrientation.Right;
                                m_popup.HorizontalOffset = position.X - tip.ActualWidth;
                                m_popup.VerticalOffset   = position.Y - targetHeight;
                                tip.Offset = targetHeight;
                            }
                            else//右
                            {
                                tip.Orientation          = ArrowTipOrientation.Left;
                                m_popup.HorizontalOffset = position.X + targetWidth;
                                m_popup.VerticalOffset   = position.Y - targetHeight;
                                tip.Offset = targetHeight;
                            }

                            if (actualHeight <= position.Y + tip.ActualHeight)
                            {
                                m_popup.VerticalOffset = actualHeight - tip.ActualHeight;
                                tip.Offset             = position.Y - m_popup.VerticalOffset;
                            }
                            else if (position.Y - tip.ActualHeight < 0)
                            {
                                m_popup.VerticalOffset = 0;
                                tip.Offset             = position.Y;
                            }
                        }
                        else
                        {
                            bool isTop = false;

                            if (position.Y + tip.ActualHeight + targetHeight > actualHeight)
                            {
                                isTop = true;
                            }

                            //左
                            if (isTop)
                            {
                                tip.Orientation          = ArrowTipOrientation.Bottom;
                                m_popup.VerticalOffset   = position.Y - tip.ActualHeight;
                                m_popup.HorizontalOffset = position.X;
                                tip.Offset = targetWidth / 2;
                            }
                            else//右
                            {
                                tip.Orientation          = ArrowTipOrientation.Top;
                                m_popup.VerticalOffset   = position.Y + targetHeight;
                                m_popup.HorizontalOffset = position.X;
                                tip.Offset = targetWidth / 2;
                            }

                            if (actualWidth <= position.X + tip.ActualWidth)
                            {
                                m_popup.HorizontalOffset = actualWidth - tip.ActualWidth;
                                tip.Offset = position.X - m_popup.HorizontalOffset;
                            }
                            else if (position.X - tip.ActualWidth < 0)
                            {
                                m_popup.HorizontalOffset = 0;
                                tip.Offset = position.X;
                            }
                        }
                    }
                }
            }
        }