Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to disable minimize button with "UseModernWindowStyle:true" #565

Open
AsaharaHiroshi opened this issue May 31, 2023 · 0 comments
Open

Comments

@AsaharaHiroshi
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant