7

As you known, when allow transparent property is true, the border of window is hidden and we cannot re-size the window. We only re-size the window if we set ResizeMode is CanResizeWithGrip, but the solution is not good because we can re-size window when it's maximized and change by right corner of the window instead of all of 4 corners, so the question is how to how to re-size window in WPF when Allow Transparent is True without using CanResizeWithGrip?

Thanks in advance!

~Thi

Thi Le
  • 183
  • 1
  • 10

3 Answers3

11

My expected is set window can re-size with hidden border, so finally I have found a solution to handle that, you can follow the below code:

<WindowChrome.WindowChrome>
    <WindowChrome     
        CaptionHeight="1"  
        CornerRadius ="0"
        ResizeBorderThickness="4"         
        GlassFrameThickness="0">
    </WindowChrome>
</WindowChrome.WindowChrome>

Please add more discussion if you want to know more information.

Thi Le
  • 183
  • 1
  • 10
  • 1
    This is the best way to do it, IMHO. We do it like this in our own solutions as well. I was about to suggest it before you posted. :) One thing I suggest is that if you have full window dragging code like `MouseLeftButtonDown += (sender, e) => DragMove();` make sure the `ResizeBorderThickness` is tested well enough so that is enough and does not conflict with the window dragging. – Dax Pandhi Oct 15 '15 at 10:35
  • Awesome! Thank you! – Ryan Nov 25 '21 at 21:20
2

Well, this is actually pretty easy. There is a property on the Window named ResizeMode, and if you set it to "CanResizeWithGrip", then a ResizeGrip control is placed on your window automatically, and if you run the app, it will, correctly, resize your window.

Mohd Ahmed
  • 1,422
  • 13
  • 27
  • Thanks for your answer @Ahmed, but I want to re-size window when allow transparent is true and without using CanResizeWithGrip. Do you have any solutions? – Thi Le Oct 15 '15 at 06:07
2

There was a similar question.
I think that it can be suitable in your case also.

How to create a WPF Window without a border that can be resized via a grip only?

To summarize,
Add hidden grips which can be rectangles or borders to your main window.
Attach below methods to events of the grip.

    [DllImport("user32.dll", CharSet = CharSet.Auto)]
    private static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);

    [DllImportAttribute("user32.dll")]
    public static extern bool ReleaseCapture();

    //Attach this to the MouseDown event of your drag control to move the window in place of the title bar
    private void WindowDrag(object sender, MouseButtonEventArgs e) // MouseDown
    {
        ReleaseCapture();
        SendMessage(new WindowInteropHelper(this).Handle,
            0xA1, (IntPtr)0x2, (IntPtr)0);
    }

    //Attach this to the PreviewMousLeftButtonDown event of the grip control in the lower right corner of the form to resize the window
    private void WindowResize(object sender, MouseButtonEventArgs e) //PreviewMousLeftButtonDown
    {
        HwndSource hwndSource = PresentationSource.FromVisual((Visual)sender) as HwndSource;
        SendMessage(hwndSource.Handle, 0x112, (IntPtr)61448, IntPtr.Zero);
    }

However, if you set AllowsTransparency to true, then it makes default WPF WebBrowser not visible, also has other downfalls.

It is very well explained in the above link.

Community
  • 1
  • 1
JasonRho
  • 106
  • 5