Kinnara / ModernWpf

Modern styles and controls for your WPF applications

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to disable minimize button with "UseModernWindowStyle:true"

AsaharaHiroshi opened this issue · comments

I would like to disable Minimize button in title bar in WPF window.
When I set ui:WindowHelper.UseModernWindowStyle="False" in xaml, I was able to implement by the following code.

[DllImport( "user32.dll" )]
static extern int GetWindowLong ( IntPtr hWnd, int nIndex );
[DllImport( "user32.dll" )]
static extern int SetWindowLong ( IntPtr hWnd, int nIndex, int dwNewLong );
private const int GWL_STYLE = -16;
private const int WS_MINIMIZEBOX = 0x20000;

protected override void OnSourceInitialized ( EventArgs e ) {
    base.OnSourceInitialized( e );
    IntPtr handle = new WindowInteropHelper( this ).Handle;
    var style = GetWindowLong( handle, GWL_STYLE );
    style &= ~WS_MINIMIZEBOX;
    _ = SetWindowLong( handle, GWL_STYLE, style );
}

However, when I set ui:WindowHelper.UseModernWindowStyle="True", this code does not work. The Minimize button is still valid.
I want to use UseModernWindowStyle="True" to apply to mode change (dark/ light mode).
Do you know how to solve this problem?