c# - DataGrid.ColumnWidth="*" not working in a ScrollViewer -


i have datagrid columnwidth="*" in scrollviewer horizontalscrollbarvisibility="auto". unfortunately combination doesn't seem work well. while datagrid spans on full window width columns super small (minwidth). if change horizontalscrollbarvisibility disabled works lose desired scrollviewer behavior.

minimal working example:

<window x:class="wpf_sandbox.mainwindow"         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"         xmlns:local="clr-namespace:wpf_sandbox"         title="mainwindow"         x:name="thiscontrol">     <scrollviewer horizontalscrollbarvisibility="auto">         <datagrid autogeneratecolumns="false" columnwidth="*">             <datagrid.columns>                 <datagridtextcolumn header="column 1" />                 <datagridtextcolumn header="column 2" />                 <datagridtextcolumn header="column 3" />                 <datagridtextcolumn header="column 4" />             </datagrid.columns>         </datagrid>     </scrollviewer> </window> 

why happening , how can work around it?

the problem see because datagrid inside scrollviewer, has virtually infinite space expand,so can't calculate widths. work can bind datagrid width scrollviewer viewportwidth, this:

<datagrid autogeneratecolumns="false" columnwidth="*"  width="{binding relativesource={relativesource findancestor,  ancestortype={x:type scrollviewer}}, path=viewportwidth}"> 

Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -