private void showRangeContextMenu(Rectangle rectangle, MouseEventArgs e)
        {
            if (rectangle == null)
            {
                return;
            }
            Point mousePos = e.GetPosition(
#if SILVERLIGHT
                Application.Current.RootVisual
#else
                Application.Current.MainWindow
#endif
                );

            // Create a popup.
            if (rangeContextMenuPopup == null)
            {
                rangeContextMenuPopup   = new Popup();
                rangeContextMenuControl = new RangeContextMenuControl();
                rangeContextMenuControl.AddRangeClick         += new RoutedEventHandler(addRange_Click);
                rangeContextMenuControl.ConfigureRangeClick   += new RoutedEventHandler(configureRange_Click);
                rangeContextMenuControl.DeleteRangeClick      += new RoutedEventHandler(deleteRange_Click);
                rangeContextMenuControl.ContextMenuMouseEnter += new MouseEventHandler(contextMenu_MouseEnter);
                rangeContextMenuControl.ContextMenuMouseLeave += new MouseEventHandler(contextMenu_MouseLeave);
                rangeContextMenuPopup.Child = rangeContextMenuControl;
            }
            rangeContextMenuControl.Tag = rectangle;
            if (RangeContextMenuChanged != null)
            {
                RangeContextMenuChanged(this, new BaseEventArgs {
                    ClickedRectangle = rectangle
                });
            }

            // Set where the popup will show up on the screen.
            rangeContextMenuPopup.VerticalOffset   = mousePos.Y + 1;
            rangeContextMenuPopup.HorizontalOffset = horizontalOffset;

            // Open the popup.
            rangeContextMenuPopup.IsOpen = true;
        }
        private void showRangeContextMenu(Rectangle rectangle, MouseEventArgs e)
        {
            if (rectangle == null)
                return;
            Point mousePos = e.GetPosition(
#if SILVERLIGHT
                Application.Current.RootVisual
#else
                Application.Current.MainWindow
#endif
                );
            // Create a popup.
            if (rangeContextMenuPopup == null)
            {
                rangeContextMenuPopup = new Popup();
                rangeContextMenuControl = new RangeContextMenuControl();
                rangeContextMenuControl.AddRangeClick += new RoutedEventHandler(addRange_Click);
                rangeContextMenuControl.ConfigureRangeClick += new RoutedEventHandler(configureRange_Click);
                rangeContextMenuControl.DeleteRangeClick += new RoutedEventHandler(deleteRange_Click);
                rangeContextMenuControl.ContextMenuMouseEnter += new MouseEventHandler(contextMenu_MouseEnter);
                rangeContextMenuControl.ContextMenuMouseLeave += new MouseEventHandler(contextMenu_MouseLeave);
                rangeContextMenuPopup.Child = rangeContextMenuControl;
            }
            rangeContextMenuControl.Tag = rectangle;
            if (RangeContextMenuChanged != null)
                RangeContextMenuChanged(this, new BaseEventArgs { ClickedRectangle = rectangle });

            // Set where the popup will show up on the screen.
            rangeContextMenuPopup.VerticalOffset = mousePos.Y + 1;
            rangeContextMenuPopup.HorizontalOffset = horizontalOffset;

            // Open the popup.
            rangeContextMenuPopup.IsOpen = true;
        }