c# - WPF fixed rows are resizing -
i'm new in wpf , try creat specific usercontrol display data single product. used grid inside usercontrol. create 5 columns , 3 rows. want ot make 4 columns fixed (image, green-clored, blue-colored , column controls) , last column (orange-colored) fill availabel space. here xaml , few screenshots:
<grid margin="0,0,0,5" background="#ffdcd9d9" > <grid.columndefinitions> <columndefinition width="80" /> <columndefinition width="70" /> <columndefinition width="70" /> <columndefinition width="70" /> <columndefinition width="*" /> </grid.columndefinitions> <grid.rowdefinitions> <rowdefinition height="auto" /> <rowdefinition height="auto" /> <rowdefinition height="auto" /> <rowdefinition height="auto" /> </grid.rowdefinitions> <image grid.column="0" grid.row="0" grid.rowspan="4" source="{binding itemthumbnailurl}" stretch="none" horizontalalignment="right" margin="5,0" /> <stackpanel grid.column="1" grid.row="0" grid.columnspan="4" background="#ffda6f6f"> <label borderthickness="0" content="dsgsdgsgsgsdgsdg sd " fontsize="13.333" fontweight="bold" horizontalalignment="left" /> </stackpanel> <stackpanel grid.column="1" grid.row="1" orientation="horizontal" background="#ff517823" horizontalalignment="left" width="70"> <label content="{binding itemprice}" horizontalalignment="left" fontsize="9.333" width="45" /> <label content="грн." horizontalalignment="left" fontsize="9.333" width="25"/> </stackpanel> <stackpanel grid.column="2" grid.row="1" orientation="horizontal" background="#ff214299" horizontalalignment="left" width="70"> <label content="{binding quantity}" horizontalalignment="left" fontsize="9.333" width="45" /> <label content="шт." horizontalalignment="left" fontsize="9.333" width="25"/> </stackpanel> <stackpanel grid.column="1" grid.row="2" orientation="horizontal" background="#ff88b91e" horizontalalignment="left" width="70"> <label content="1С" horizontalalignment="right" fontsize="9.333" foreground="#ff8b8888" width="45"/> <label content="грн." horizontalalignment="right" fontsize="9.333" foreground="#ff8b8888" width="25"/> </stackpanel> <stackpanel grid.column="2" grid.row="2" orientation="horizontal" background="#ff228cbd" horizontalalignment="left" width="70"> <label content="1С" horizontalalignment="right" fontsize="9.333" foreground="#ff8b8888" width="45"/> <label content="шт." horizontalalignment="right" fontsize="9.333" foreground="#ff8b8888" width="25"/> </stackpanel> <checkbox grid.column="3" grid.row="1" horizontalalignment="center" verticalalignment="center"/> <button grid.column="3" grid.row="2" background="{x:null}" content="Редакт." foreground="#ff444343" width="50" horizontalalignment="center" verticalalignment="center" /> <label grid.column="4" grid.rowspan="2" grid.row="1" background="#ffe08212" horizontalcontentalignment="stretch" /> </grid>
if have "title" text (in red-colored cell) less sum of 3 fixed columns, ok, if text larger have problems paddings between columns (please see pictures)
so how can resolve problem?
i reproduce issue in variety of cases when grid used in datatemplate. removed stackpanel
, used textblock
, a textblock
hosted in separate grid
, same result. guess going wrong when wpf determining required size. have occurred kind of strange behaviour in grids (when part of itemtemplate). if need quick workaround should trick
<grid.columndefinitions> <columndefinition minwidth="80" maxwidth="80" /> <columndefinition minwidth="70" maxwidth="70" /> <columndefinition minwidth="70" maxwidth="70" /> <columndefinition minwidth="70" maxwidth="70" /> <columndefinition width="*" /> </grid.columndefinitions> <grid.rowdefinitions> <rowdefinition height="auto" /> <rowdefinition height="auto" /> <rowdefinition height="auto" /> <rowdefinition height="auto" /> </grid.rowdefinitions>
Comments
Post a Comment