Exemple #1
0
        private void ShowKeyboardAtLocation(Button btn, int offsetX, int offsetY)
        {
            Window window = Window.GetWindow(this);
            Point pt0 = this.TransformToAncestor(window).Transform(new Point(0, 0));
            Point pt1 = btn.TranslatePoint(new Point(), this);

            int left = (int)(pt0.X + pt1.X) + offsetX;
            int top = (int)(pt0.Y + pt1.Y) + offsetY;

            var hwnd = ((HwndSource)PresentationSource.FromVisual(this.ModalDialog.Child)).Handle;

            RECT rect;
            if (GetWindowRect(hwnd, out rect))
            {
                SetWindowPos(hwnd, -2, left, top, -1, -1, 0);
            }
        }
        //private double newTop = 50;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="origin">which raise the event</param>
        /// <param name="dst">new postion for the original control</param>
        /// <param name="screen">backgroud image split</param>
        public SplitScreen(Button origin,Point dst, Grid screen): this()
        {
            //this.Background = screen.Background;

            //copy button
            buttonOldPoint = origin.TranslatePoint(new Point(0, 0), screen);

            //TO-DO add some logic
            buttonNewPoint.X = buttonOldPoint.X ;
            buttonNewPoint.Y = buttonOldPoint.Y ;

            splitLine = buttonOldPoint.Y + interval + origin.Height;

            button = new ProgressButton();

            button.Content = origin.Content;
            button.Width = origin.Width;
            button.Height = origin.Height;

            button.FirstImage = (origin as ProgressButton).FirstImage;
            button.SecondImage = (origin as ProgressButton).SecondImage;
            button.CoverImage = (origin as ProgressButton).CoverImage;
            button.RotatedImage = (origin as ProgressButton).RotatedImage;

            button.State = State.Normal;
            button.Click += new RoutedEventHandler(button_Click);

            Canvas.SetLeft(button, buttonOldPoint.X);
            Canvas.SetTop(button, buttonOldPoint.Y);

            this.canvas.Children.Add(button);

            //copy background
            var background = new RenderTargetBitmap((int)screen.ActualWidth, (int)screen.ActualHeight, 
                                                    96d, 96d, PixelFormats.Pbgra32);
            background.Render(screen);

            int height = (int)background.Height;
            int width = (int)background.Width;
            
            var top = new CroppedBitmap(background, new Int32Rect(0, 0, width, (int)splitLine));
            var bottom = new CroppedBitmap(background, new Int32Rect(0, (int)splitLine, width, (int)(height - splitLine)));

            bg_top.Source = top;
            bg_bottom.Source = bottom;

            bg_top.Width = width;
            bg_top.Height = splitLine;

            bg_bottom.Width = width;
            bg_bottom.Height = height - splitLine;

            //generata container
            this.Container.Width = width;
            this.Container.Height = 300;

            //animation
            double verticalMove = buttonOldPoint.Y - buttonNewPoint.Y;

            translate(bg_top, 0, -verticalMove);
            translate(button, buttonOldPoint.Y, buttonNewPoint.Y);
            translate(Container, splitLine, splitLine - verticalMove);
            translate(bg_bottom, splitLine, splitLine + (Container.Height - verticalMove));
        }