Example #1
0
        private void CreatePopupWindow()
        {
            if (selectedToolBoxItem == null)
            {
                return;
            }

            Popup = new System.Windows.Window();

            Popup.Topmost = true;

            Border border = new Border();

            border.BorderBrush     = Brushes.Black;
            border.Background      = System.Windows.Media.Brushes.WhiteSmoke;
            border.BorderThickness = new Thickness(2);

            Popup.Content         = border;
            border.Child          = selectedToolBoxItem.CreateToggleButtonContent();
            Popup.Width           = selectedToolBoxItem.ToggleButton.ActualWidth;
            Popup.Height          = selectedToolBoxItem.ToggleButton.ActualHeight + 12;
            Popup.WindowStyle     = WindowStyle.None;
            Popup.ShowInTaskbar   = false;
            Popup.PreviewMouseUp += new MouseButtonEventHandler(Popup_PreviewMouseUp);
            Popup.CaptureMouse();
        }
        public void OpenPopup(bool UseMouse)
        {
            root = FindWindow(this);
            isMouseMode = UseMouse;
            if (root == null)
                return;
            this.Visibility = Visibility.Collapsed;
            overlay = new Canvas();
            RenderTargetBitmap content = new RenderTargetBitmap((int)root.ActualWidth, (int)root.ActualHeight, 96, 96, PixelFormats.Pbgra32);
            content.Render(root);
            _contentLayer = new Image() { Source = content, Width = root.ActualWidth, Height = root.ActualHeight };
            overlay.Children.Add(_contentLayer);
            overlay.Width = root.ActualWidth;
            overlay.Height = root.ActualHeight;

            mask.Opacity = 0;
            mask.Width = root.ActualWidth;
            mask.Height = root.ActualHeight;
            overlay.Children.Add(mask);

            myContent = this.Content as FrameworkElement;
            myContentSize = new Size(myContent.ActualWidth, myContent.ActualHeight);
            this.Content = null;
            selfLayer = new ContentControl() { Content = myContent };
            selfLayer.Width = myContentSize.Width; selfLayer.Height = myContentSize.Height;
            myContent.Width = myContent.Width; myContent.Height = myContent.Height;
            overlay.Children.Add(selfLayer);
            Point location = this.TranslatePoint(new Point(0, 0), root);
            selfLayer.SetValue(Canvas.LeftProperty, location.X);
            selfLayer.SetValue(Canvas.TopProperty, location.Y);
            myContent.Visibility = Visibility.Visible;
            oldContent = root.Content;
            oy = Mouse.GetPosition(root).Y;
            root.Content = overlay;
            overlay.IsEnabled = false;
            orginValue = Value;

            AnimateContent(1, 1.08, new EventHandler((sender, e) => { overlay.IsEnabled = true; }));
            //mask.MouseDown += new MouseButtonEventHandler(_contentLayer_MouseDown);
            root.SizeChanged += new SizeChangedEventHandler(root_SizeChanged);
            myContent.Effect = new DropShadowEffect() { ShadowDepth = 0 };
            lastTick = Environment.TickCount;
            if (UseMouse)
            {
                root.MouseMove += new MouseEventHandler(root_MouseMove);
                root.MouseLeftButtonUp += new MouseButtonEventHandler(root_MouseLeftButtonUp);
                root.CaptureMouse();
            }
            else
            {
                root.ManipulationDelta += new EventHandler<ManipulationDeltaEventArgs>(root_ManipulationDelta);
                root.ManipulationCompleted += new EventHandler<ManipulationCompletedEventArgs>(root_ManipulationCompleted);
            }
        }