c# - The objects inside the xaml form are being scrambled (resized or hidden) after resizing main window? -
i have problem in resizing main window of app.xaml form: after resizing it, objects (buttons,combo boxes, textboxes, etc) inside form being resized, hidden or moved place in form. want resize main window not other objects. in other words, want unlink these 2 (main window & other objects) each other. after doing that, can resize main window , then, manually move objects new place in form. code of form given below.
<window x:class="wpfclient.window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" title="window1" height="550" width="834" maxheight="550" maxwidth="834" minheight="550" minwidth="834"> <grid> <grid.background> <lineargradientbrush> <gradientstop color="lightslategray" offset="0"/> <gradientstop color="white" offset="0.5"/> <gradientstop color="lightslategray" offset="0.9"/> </lineargradientbrush> </grid.background> <label x:name="loginlabeluname" height="25" horizontalalignment="left" margin="179,200,0,0" verticalalignment="top" width="70">user name: </label> <textbox x:name="logintxtboxuname" height="23" margin="277,200,313,0" verticalalignment="top" /> <label x:name="loginlabelip" horizontalalignment="left" margin="179,232,0,255" width="70">service ip:</label> <textbox x:name="logintxtboxip" margin="277,232,313,0" text="41.235.135.104" height="23" verticalalignment="top" /> <button x:name="loginbuttonconnect" background="transparent" margin="277,0,313,222" click="buttonconnect_click" height="23" verticalalignment="bottom">connect</button> <label x:name="loginlabelstatus" height="44" verticalalignment="bottom" fontfamily="jokerman" fontsize="20" foreground="white" horizontalalignment="right" width="167" margin="0,0,40,71">offline</label> <combobox x:name="logincomboboximgs" horizontalalignment="right" margin="0,200,197,222" width="98" background="transparent" /> <label x:name="loginlabeltitle" height="57" fontfamily="jokerman" fontsize="25" foreground="white" margin="16,16,0,0" verticalalignment="top" horizontalalignment="left" width="293">wcf / wpf chat app.</label> <polyline x:name="loginpolyline" strokethickness="2" stroke="white" points="140,90 140,300 700,300 700,90 140,90" margin="-9,42,116,165" /> <listbox x:name="chatlistboxmsgs" margin="10,62,167,84" /> <listbox x:name="chatlistboxnames" horizontalalignment="right" margin="0,62,10,84" width="139" /> <checkbox x:name="chatcheckboxwhisper" height="15" horizontalalignment="right" margin="0,37,10,0" verticalalignment="top" width="120" foreground="white" fontsize="12">whisper mode</checkbox> <textbox x:name="chattxtboxtype" height="39" margin="10,0,313,9" verticalalignment="bottom" /> <button x:name="chatbuttonsend" click="chatbuttonsend_click" height="39" margin="0,0,167,9" verticalalignment="bottom" horizontalalignment="right" width="136">send</button> <button x:name="chatbuttondisconnect" click="chatbuttondisconnect_click" height="39" horizontalalignment="right" margin="0,0,10,9" verticalalignment="bottom" width="139">disconnect</button> <image x:name="chatcurrentimage" horizontalalignment="left" margin="10,0,0,0" stretch="fill" width="60" height="70" verticalalignment="top" /> <label x:name="chatlabelcurrentuname" height="23" horizontalalignment="left" margin="87,10,0,0" verticalalignment="top" width="85" foreground="white"></label> <label x:name="chatlabelcurrentstatus" height="23" margin="87,37,0,0" verticalalignment="top" foreground="green" horizontalalignment="left" width="85"></label> <label x:name="chatlabelwritingmsg" height="30" margin="10,0,167,49" verticalalignment="bottom" foreground="gray"></label> <button x:name="chatbuttonsendfile" click="chatbuttonsendfile_click" background="transparent" height="23" margin="270,10,0,0" verticalalignment="top" horizontalalignment="left" width="105">send file</button> <label x:name="chatlabelsendfilestatus" height="28" margin="270,32,316,0" verticalalignment="top"></label> <button x:name="chatbuttonopenreceived" click="chatbuttonopenreceived_click" background="transparent" height="23" margin="382,10,313,0" verticalalignment="top">open received files</button> </grid> </window>
the reason why occurring because explicitly setting margin properties on elements.
margin="277,232,313,0" these margins relative parent grid. code above says:
place element 277 left, 232 top, 313 right , 0 bottom.
therefore, when grid gets resized, these margins recalculated, , thus, screw positioning of elements.
to combat this, should using relative positioning. there answer question here.
Comments
Post a Comment