c# - How can the maximize button of a WPF window be correctly disabled at runtime? -
i'm trying disable maximize button of wpf window @ runtime: when click on "disable" button maximize button should disabled.
accomplish i'm using following code:
private const int gwl_style = -16; private const int ws_maximizebox = 0x10000; [dllimport( "user32.dll" )] private static extern int getwindowlong( intptr hwnd, int nindex ); [dllimport( "user32.dll" )] private static extern int setwindowlong( intptr hwnd, int nindex, int dwnewlong ); public static void disablemaximizeof( window window ) { intptr winhandle = new windowinterophelper( window ).handle; // current style , remove ws_maximizebox bits int style = getwindowlong( winhandle, gwl_style ); setwindowlong( winhandle, gwl_style, style & ~ws_maximizebox ); } after disablemaximizeof(...) called maximize-functionality correctly disabled - problem maximize button still looks before:

if minimize window , restore again, button correctly displayed:

so tried refresh gui, nothing seemed work. there solution this? appreciated.
this taken directly pinvoke.net
certain window data cached, changes make using setwindowlong not take effect until call setwindowpos function. specifically, if change of frame styles, must call setwindowpos swp_framechanged flag cache updated properly.
Comments
Post a Comment