WPF window maximize with fixed/limited width -


on wpf window, have set

width="300" minwidth="300" maxwidth="300" 

when maximize window, docks left screen border fixed with, bottom part of window underneath windows 8 taskbar.

i have tried

public mainwindow() {     ...     this.maxheight = system.windows.systemparameters.workarea.height; } 

, results in few pixels of free space between taskbar , app.

i'd

  • have fixed width window
  • dock right border on maximize
  • not cover/go under taskbar in maximized state

unfortunately, 3 requirements not seem achievable using minwidth, maxwidth , windowstate.

but regardless, it's still possible achieve similar. need emulate maximized state of window. need move window correct position, right height, , make unmovable. first 2 parts easy, last 1 requires more advanced stuff.

start out window have, width, maxwidth , minwidth set 300, , add event handler statechanged.

width="300" minwidth="300" maxwidth="300" statechanged="mainwindow_onstatechanged" 

and event handler, , helper methods:

private bool ismaximized; private rect normalbounds; private void mainwindow_onstatechanged(object sender, eventargs e) {     if (windowstate == windowstate.maximized && !ismaximized)     {         windowstate = windowstate.normal;         ismaximized = true;          normalbounds = restorebounds;          height = systemparameters.workarea.height;         maxheight = height;         minheight = height;         top = 0;         left = systemparameters.workarea.right - width;         setmovable(false);     }     else if(windowstate == windowstate.maximized && ismaximized)     {         windowstate = windowstate.normal;         ismaximized = false;          maxheight = double.positiveinfinity;         minheight = 0;          top = normalbounds.top;         left = normalbounds.left;         width = normalbounds.width;         height = normalbounds.height;         setmovable(true);     } }  private void setmovable(bool enable) {     hwndsource source = hwndsource.fromhwnd(new windowinterophelper(this).handle);      if(enable)         source.removehook(wndproc);     else         source.addhook(wndproc); }  private static intptr wndproc(intptr hwnd, int msg, intptr wparam, intptr lparam, ref bool handled) {     const int wm_syscommand = 0x0112;     const int sc_move = 0xf010;      switch (msg)     {         case wm_syscommand:             int command = wparam.toint32() & 0xfff0;             if (command == sc_move)                 handled = true;             break;     }      return intptr.zero; } 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -