Exemplo n.º 1
0
            public void Dispose()
            {
                if (_shouldUpdatePosition)
                {
                    _shouldUpdatePosition = false;

                    if (_contextMenu != null)
                    {
                        _contextMenu.ClearValue(ContextMenu.HorizontalOffsetProperty);
                        _contextMenu.ClearValue(ContextMenu.VerticalOffsetProperty);
                    }
                    else if (_toolTip != null)
                    {
                        _toolTip.ClearValue(System.Windows.Controls.ToolTip.HorizontalOffsetProperty);
                        _toolTip.ClearValue(System.Windows.Controls.ToolTip.VerticalOffsetProperty);
                    }
                    else if (_popup != null)
                    {
                        _popup.ClearValue(Popup.HorizontalOffsetProperty);
                        _popup.ClearValue(Popup.VerticalOffsetProperty);
                    }
                }

                _contextMenu = null;
                _toolTip     = null;
                _popup       = null;
            }
Exemplo n.º 2
0
        private static void SetAllowsTransparencyInternal(Control element, Object value)
        {
            ToolTip     tooTip      = element as ToolTip;
            ContextMenu contextMenu = element as ContextMenu;

            // Set the IsOpen property to true to let the ToolTip/ContextMenu create Popup instance early, since
            // we are only interesting in Popup.AllowsTransparency property rather than
            // opening the ToolTip/ContextMenu, set its Visibility to Collapsed.
            element.Visibility = Visibility.Collapsed;
            if (tooTip != null)
            {
                tooTip.IsOpen = true;
            }
            else if (contextMenu != null)
            {
                contextMenu.IsOpen = true;
            }

            //Find the Popup logical element root.
            Popup popup = GetPopupFromVisualChild(element);

            if (popup != null)
            {
                popup.SetValue(Popup.AllowsTransparencyProperty, value);
            }

            //Set properties back to what it is initially.
            if (tooTip != null)
            {
                tooTip.ClearValue(ToolTip.IsOpenProperty);
            }
            else if (contextMenu != null)
            {
                contextMenu.ClearValue(ToolTip.IsOpenProperty);
            }
            element.ClearValue(FrameworkElement.VisibilityProperty);
        }