xaml - vertical scrollbar not apearing in datagrid inside usercontrol in wpf -
i have user control in wpf has datagrid. add user control in window inside tabitem of tabcontrol. vertical scrollbar not getting visible. resized window , seems user control taking complete height after considering height of datagrid.
how make vertical scrollbar appear , still keep height of datagrid auto depending on height available per height of user control , window ?
edit: main window:
<window> <grid> <tabcontrol name="tc" selectionchanged="tc_selectionchanged"> <tabitem header="abc"> <local:uc1 /> </tabitem> <tabitem header="def"> <local:uc2 /> </tabitem> </tabcontrol> </grid> </window>
user control:
<usercontrol> <grid> <grid.rowdefinitions> <rowdefinition height="auto"></rowdefinition> <rowdefinition height="30"></rowdefinition> </grid.rowdefinitions> <grid.columndefinitions> <columndefinition width="2*"></columndefinition> <columndefinition width="*"></columndefinition> </grid.columndefinitions> <stackpanel grid.row="0" grid.column="0" orientation="vertical"> <stackpanel orientation="horizontal"> <button>add</button> <button>remove</button> <button>refresh</button> </stackpanel> <label name="lbltopmessage">some message</label> <datagrid name="dg" isreadonly="true"> <datagrid.columns> <datagridtextcolumn binding="{binding name}" header="name" width="*"></datagridtextcolumn> <datagridtextcolumn binding="{binding value}" header="value" width="130"></datagridtextcolumn> <datagridtextcolumn binding="{binding list}" header="list" width="*"></datagridtextcolumn> </datagrid.columns> </datagrid> </stackpanel> <grid grid.row="0" grid.column="1" name="gridts"> <grid.rowdefinitions> <rowdefinition height="auto"></rowdefinition> <rowdefinition height="auto"></rowdefinition> <rowdefinition height="auto"></rowdefinition> <rowdefinition height="auto"></rowdefinition> <rowdefinition height="auto"></rowdefinition> <rowdefinition height="auto"></rowdefinition> </grid.rowdefinitions> <grid.columndefinitions> <columndefinition width="100"></columndefinition> <columndefinition width="*"></columndefinition> </grid.columndefinitions> <textblock name="lblnewsource" grid.row="0" grid.columnspan="2" horizontalalignment="center" padding="0 5 0 0" fontweight="bold">new source</textblock> <textblock grid.row="1" grid.column="0" padding="10 10 0 0">name:</textblock> <textblock grid.row="2" grid.column="0" padding="10 10 0 0">value:</textblock> <textblock grid.row="3" grid.column="0" padding="10 10 0 0">list:</textblock> <textbox grid.row="1" grid.column="1" name="txtname" isenabled="false"></textbox> <combobox grid.row="2" grid.column="1" name="cbvalue"></combobox> <listbox grid.row="3" grid.column="1" name="lblist"> <listbox.itemtemplate> <datatemplate> <checkbox margin="3 5 0 3" content="{binding name}" ischecked="{binding isactive}" /> </datatemplate> </listbox.itemtemplate> </listbox> <button name="btnsave" click="btnsave_click" grid.row="4" grid.column="1">save</button> <textblock textwrapping="wrapwithoverflow" name="lblmessage" grid.row="5" grid.column="1" margin="0 10 10 0"></textblock> </grid> </grid> </usercontrol>
updated: took datagrid out of stackpanel. try code:
<grid> <grid.rowdefinitions> <rowdefinition height="45.361"></rowdefinition> <rowdefinition height="102.639" /> <rowdefinition height="30"></rowdefinition> </grid.rowdefinitions> <grid.columndefinitions> <columndefinition width="2*"></columndefinition> <columndefinition width="*"></columndefinition> </grid.columndefinitions> <stackpanel grid.row="0" grid.column="0" orientation="vertical"> <stackpanel orientation="horizontal"> <button>add</button> <button>remove</button> <button>refresh</button> </stackpanel> <label name="lbltopmessage">some message</label> </stackpanel> <datagrid grid.row="1" name="dg" isreadonly="true"> <datagrid.columns> <datagridtextcolumn binding="{binding name}" header="name" width="*"></datagridtextcolumn> <datagridtextcolumn binding="{binding value}" header="value" width="130"></datagridtextcolumn> <datagridtextcolumn binding="{binding list}" header="list" width="*"></datagridtextcolumn> </datagrid.columns> </datagrid> <grid grid.row="0" grid.column="1" name="gridts" grid.rowspan="2"> <grid.rowdefinitions> <rowdefinition height="auto"></rowdefinition> <rowdefinition height="auto"></rowdefinition> <rowdefinition height="auto"></rowdefinition> <rowdefinition height="auto"></rowdefinition> <rowdefinition height="auto"></rowdefinition> <rowdefinition height="auto"></rowdefinition> </grid.rowdefinitions> <grid.columndefinitions> <columndefinition width="100"></columndefinition> <columndefinition width="*"></columndefinition> </grid.columndefinitions> <textblock name="lblnewsource" grid.row="0" grid.columnspan="2" horizontalalignment="center" padding="0 5 0 0" fontweight="bold">new source</textblock> <textblock grid.row="1" grid.column="0" padding="10 10 0 0">name:</textblock> <textblock grid.row="2" grid.column="0" padding="10 10 0 0">value:</textblock> <textblock grid.row="3" grid.column="0" padding="10 10 0 0">list:</textblock> <textbox grid.row="1" grid.column="1" name="txtname" isenabled="false"></textbox> <combobox grid.row="2" grid.column="1" name="cbvalue"></combobox> <listbox grid.row="3" grid.column="1" name="lblist"> <listbox.itemtemplate> <datatemplate> <checkbox margin="3 5 0 3" content="{binding name}" ischecked="{binding isactive}" /> </datatemplate> </listbox.itemtemplate> </listbox> <button name="btnsave" grid.row="4" grid.column="1">save</button> <textblock textwrapping="wrapwithoverflow" name="lblmessage" grid.row="5" grid.column="1" margin="0 10 10 0"></textblock> </grid> </grid>
i hope helps.
Comments
Post a Comment