Exemplo n.º 1
0
        /// <summary>
        /// Adds the popup control.
        /// </summary>
        /// <param name="parentPanel">The parent panel.</param>
        /// <returns>PopupView.</returns>
        private PopupView AddPopupControl(Panel parentPanel)
        {
            var popupView = new PopupView
                                {
                                    Name = string.Format(CultureInfo.InvariantCulture, "popupDialog{0}", parentPanel.Children.Count),
                                    DataContext = this,
                                    IsHitTestVisible = true,
                                    Visibility = Visibility.Visible,
                                };

            switch (_position)
            {
                case PopupPosition.Top:
                case PopupPosition.Right:
                    {
                        popupView.HorizontalAlignment = HorizontalAlignment.Right;
                        popupView.VerticalAlignment = VerticalAlignment.Bottom;
                        popupView.Margin = new Thickness(0, 0, -50, 5);
                        popupView.RenderTransformOrigin = new Point(0.5, 0.5);

                        var transform = new CompositeTransform { Rotation = 0, ScaleX = 1, ScaleY = 1, SkewX = 0, SkewY = 0 };
                        switch (_position)
                        {
                            case PopupPosition.Right:
                                transform.TranslateX = 280;
                                transform.TranslateY = 0;
                                break;
                            case PopupPosition.Top:
                                transform.TranslateX = 0;
                                transform.TranslateY = 0;
                                break;
                        }

                        popupView.RenderTransform = transform;
                    }

                    break;
                case PopupPosition.Center:
                    popupView.HorizontalAlignment = HorizontalAlignment.Center;
                    popupView.VerticalAlignment = VerticalAlignment.Center;
                    popupView.IsCentered = true;
                    popupView.SizeChanged += PopupView_SizeChanged;
                    break;
                default:
                    popupView.HorizontalAlignment = HorizontalAlignment.Left;
                    popupView.VerticalAlignment = VerticalAlignment.Top;
                    popupView.Margin = new Thickness(_location.X, _location.Y - 10, 0, 0);
                    popupView.IsCentered = true;
                    popupView.SizeChanged += PopupView_SizeChanged;
                    break;
            }

            ZIndex = ThePopupFactory.Value.NextZIndex();
            if (_modalBorder != null)
                ZIndex = Canvas.GetZIndex(_modalBorder) + 1;
            popupView.SetValue(Canvas.ZIndexProperty, ZIndex);
            popupView.Name = Guid.NewGuid().ToString();
            parentPanel.Children.Insert(0, popupView);
            ThePopupFactory.Value.Popups.Add(this);
            popupView.MouseEnter += _popupView_MouseEnter;
            popupView.MouseLeave += _popupView_MouseLeave;

            Application.Current.RootVisual.AddHandler(UIElement.KeyDownEvent, new KeyEventHandler(RootVisual_KeyDown), true);

            return popupView;
        }