c# - Distribute columns evenly in WPF DataGrid -
i have window set sizetocontent="widthandheight"
, in window there row of controls want define width of window. underneath controls datagrid 3 columns.
however can't seem evenly distribute 3 columns same size , use space available. there way in c#.net?
you can via databinding. example:
<window x:class="wpfapplication2.mainwindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" title="mainwindow" sizetocontent="widthandheight"> <stackpanel orientation="vertical"> <stackpanel orientation="horizontal" x:name="panel"> <label content="1" width="90"/> <label content="2" width="90"/> <label content="3" width="90"/> </stackpanel> <datagrid width="{binding actualwidth, elementname=panel}"> <datagrid.columns> <datagridtextcolumn header="1" width="*"/> <datagridtextcolumn header="2" width="*"/> </datagrid.columns> </datagrid> </stackpanel> </window>
Comments
Post a Comment