WPFメモ-Popupドラッグ

8511 ワード

MSDNを見てみると、PopupにはDrag関連の属性やメソッドがないことがわかり、最初にthumbを考えました.しばらく忙しくしていたが、強いgoogleを思い出した.
中国語の資料が少ないことを発見して、英語の発見は2編とても悪くなくて、だからノートはブログ園の中で、園の中の友达に役に立つことを望みます.

social.msdm
stackoverflow
スレ主はsocialを推奨する.msdmの方法は、よく試してみました.
<Popup Name="puSkills" Placement="MousePoint" PopupAnimation="Scroll" AllowsTransparency="True" IsEnabled="True" IsOpen="False">

                        <Border BorderBrush="DarkCyan" BorderThickness="3">

                            <StackPanel Background="AliceBlue" VerticalAlignment="Center" Height="400" Width="400">

                                <Label Name="lblCaption"  FontWeight="Bold" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Foreground="Blue" Background="Blue" MouseLeftButtonDown="lblCaption_MouseLeftButtonDown">Move</Label>

                                <StackPanel>



                                  <TextBlock HorizontalAlignment="Right">

                                       Some Contents...........                                          

                                    </TextBlock>

                                </StackPanel>

                            </StackPanel>

                        </Border>

                    </Popup>

バックグラウンドCSコード:
 [DllImport("user32.dll")]

        public static extern IntPtr WindowFromPoint(POINT Point);



        [DllImport("user32.dll")]

        [return: MarshalAs(UnmanagedType.Bool)]

        public static extern bool GetCursorPos(out POINT lpPoint);



        [DllImportAttribute("user32.dll")]

        public static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);



        [DllImportAttribute("user32.dll")]

        public static extern bool ReleaseCapture();



        [StructLayout(LayoutKind.Sequential)]

        public struct POINT

        {

            public int X;

            public int Y;

        }



        public const int WM_NCLBUTTONDOWN = 0xA1;

        public const int HT_CAPTION = 0x2;



 private void lblCaption_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)

        {

            POINT curPos;

            IntPtr hWndPopup;



            GetCursorPos(out curPos);

            hWndPopup = WindowFromPoint(curPos);



            ReleaseCapture();

            SendMessage(hWndPopup, WM_NCLBUTTONDOWN, new IntPtr(HT_CAPTION), IntPtr.Zero);

        }

Click the Move Content in label.. then move the mouse. Thank you!