My first row looks something like this:
Title 1 2 3 4 5 6 7 ...
If I choose
ColumnWidth="Auto"
it sizes it correctly, but there is too much space between the columns. Is there a way to shrink that? I tried in the code behind my xaml where I get the data to do
if (textColumn != 0) {
textColumn.Width = 8;
}
or something along those lines, but the size doesn’t seem to change. I’m not sure if this is correct as I’m new to WPF and C#. Thanks.
Edit:
XAML:
<DataGrid x:Name="dtGridReads" AutoGenerateColumns="False"
VirtualizingStackPanel.IsVirtualizing="True"
VirtualizingStackPanel.VirtualizationMode ="Standard"
EnableColumnVirtualization="True"
EnableRowVirtualization="True"
ScrollViewer.IsDeferredScrollingEnabled="True"
CanUserReorderColumns="False" CanUserResizeColumns="False" CanUserSortColumns="True"
ItemsSource ="{Binding}" Block.TextAlignment="Center"
AlternatingRowBackground="LightGoldenrodYellow" RowBackground="White"
CanUserAddRows="False" CanUserDeleteRows="False" FrozenColumnCount="1"
GridLinesVisibility="None" Style="{StaticResource ConcensusDataGridStyle}" FontSize="12" >
</DataGrid>
You will need to create a column width converter class and pass in a value to the converter to set your size accordingly.
Here is the converter
Here is the usage in XAML
Note that the values you pass in must be whole numbers if you are building a regional application. If you are using decimals in xaml and the local uses , for the decimal – it will EXPLODE.