WPF DataGrid window resize does not resize DataGridColumns -


i have wpf datagrid (from wpftoolkit package) following in application.

<controls:datagrid>             <controls:datagrid.columns>                 <controls:datagridtextcolumn width="1*" binding="{binding path=column1}" header="column 1" />                 <controls:datagridtextcolumn width="1*" binding="{binding path=column2}" header="column 2" />                 <controls:datagridtextcolumn width="1*" binding="{binding path=column3}" header="column 3" />     </controls:datagrid.columns> </controls:datagrid> 

the column width should automatically adjusted such 3 columns fill width of grid, set width="1*" on every column. encountered 2 problems approach.

  1. when itemssource of datagrid null or empty list, columns won't size fit width of grid have fixed width of 20 pixel. please see following picture: http://img169.imageshack.us/img169/3139/initialcolumnwidth.png
  2. when maximize application window, columns won't adapt size keep initial size. see following picture: http://img88.imageshack.us/img88/9362/columnwidthaftermaximiz.png
  3. when resize application window mouse, columns won't resize.

i able solve problem #3 deriving sub class datagrid , override datagrid's onrendersizechanged method follows.

protected override void onrendersizechanged(sizechangedinfo sizeinfo) {     base.onrendersizechanged(sizeinfo);     foreach (var column in columns)     {         var tmp = column.getvalue(datagridcolumn.widthproperty);         column.clearvalue(datagridcolumn.widthproperty);         column.setvalue(datagridcolumn.widthproperty, tmp);     } } 

unfortunately not solve problems #1 , #2. how can rid of them?

i have same problem instead of listening rendersizechanged, listened sizechanged event , accounts of situations.

datagrid.sizechanged += (sender_, arg_) =>         {           foreach (var datagridcolumn in datagrid.columns)           {             datagridlength datagridlength = datagridcolumn.width;             datagridcolumn.clearvalue(datagridcolumn.widthproperty);             datagridcolumn.width = datagridlength;           }         }; 

Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -