private static void OnWindowSourceInitialized(object sender, System.EventArgs e)
        {
            Window window = (Window)sender;

            System.IntPtr hWnd = new WindowInteropHelper(window).Handle;
            ControlBox.UpdateStyle(window, hWnd);
            ControlBox.UpdateExtendedStyle(window, hWnd);
            window.SourceInitialized -= new System.EventHandler(ControlBox.OnWindowSourceInitialized);
        }
        private static void UpdateExtendedStyle(Window window, System.IntPtr hWnd)
        {
            int style = ControlBox.NativeMethods.GetWindowLong(hWnd, -20);

            if (ControlBox.GetHasHelpButton(window))
            {
                style |= 1024;
            }
            else
            {
                style &= 1025;
            }
            ControlBox.NativeMethods.SetWindowLong(hWnd, -20, style);
        }
        private static void OnControlBoxChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            Window window = d as Window;

            if (window != null)
            {
                System.IntPtr hWnd = new WindowInteropHelper(window).Handle;
                if (hWnd == System.IntPtr.Zero)
                {
                    window.SourceInitialized += new System.EventHandler(ControlBox.OnWindowSourceInitialized);
                }
                else
                {
                    ControlBox.UpdateStyle(window, hWnd);
                    ControlBox.UpdateExtendedStyle(window, hWnd);
                }
            }
        }
        private static void UpdateStyle(Window window, System.IntPtr hWnd)
        {
            int style = ControlBox.NativeMethods.GetWindowLong(hWnd, -16);

            if (ControlBox.GetHasMaximizeButton(window))
            {
                style |= 65536;
            }
            else
            {
                style &= -65537;
            }
            if (ControlBox.GetHasMinimizeButton(window))
            {
                style |= 131072;
            }
            else
            {
                style &= -131073;
            }
            ControlBox.NativeMethods.SetWindowLong(hWnd, -16, style);
        }